File: __init__.py

package info (click to toggle)
freedombox 26.2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 82,976 kB
  • sloc: python: 48,504; javascript: 1,736; xml: 481; makefile: 290; sh: 167; php: 32
file content (87 lines) | stat: -rw-r--r-- 3,093 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# SPDX-License-Identifier: AGPL-3.0-or-later
"""
FreedomBox app for System Monitoring (cockpit-pcp) in ‘System’.
"""

from django.utils.translation import gettext_lazy as _

from plinth import app as app_module
from plinth import menu
from plinth.daemon import Daemon
from plinth.modules.backups.components import BackupRestore
from plinth.package import Package, Packages

from . import manifest

name = _('Performance')

_description = [
    _('Performance app allows you to collect, store and view information '
      'about utilization of the hardware. This can give you basic insights '
      'into usage patterns and whether the hardware is overloaded by users '
      'and services.'),
    _('Performance metrics are collected by Performance Co-Pilot and can be '
      'viewed using the Cockpit app.'),
]


class PerformanceApp(app_module.App):
    """FreedomBox app for Performance."""

    app_id = 'performance'

    _version = 1

    def __init__(self) -> None:
        """Create components for the app."""
        super().__init__()

        info = app_module.Info(app_id=self.app_id, version=self._version,
                               name=_('Performance'), icon='fa-bar-chart',
                               description=_description,
                               manual_page='Performance',
                               clients=manifest.clients, tags=manifest.tags)
        self.add(info)

        menu_item = menu.Menu('menu-performance', info.name, info.icon,
                              info.tags, 'performance:index',
                              parent_url_name='system:administration',
                              order=40)
        self.add(menu_item)

        packages = Packages('packages-performance', [
            # For bookworm, we need cockpit-pcp (which depends on
            # cockpit-bridge and pcp). For trixie, cockpit-pcp is
            # replaced by cockpit-bridge, and we need to specify a
            # dependency on pcp. There is some issue with having a
            # virtual package specified, see #2475.
            Package('cockpit-pcp') | Package('cockpit-bridge'),
            'cockpit-bridge', 'pcp'
        ])
        self.add(packages)

        backup_restore = BackupRestore('backup-restore-performance',
                                       **manifest.backup)
        self.add(backup_restore)

        daemon_0 = Daemon('daemon-performance-0', 'pmcd.service',
                          listen_ports=None)
        self.add(daemon_0)

        daemon_1 = Daemon('daemon-performance-1', 'pmie.service',
                          listen_ports=None)
        self.add(daemon_1)

        daemon_2 = Daemon('daemon-performance-2', 'pmlogger.service',
                          listen_ports=None)
        self.add(daemon_2)

        daemon_3 = Daemon('daemon-performance-3', 'pmproxy.service',
                          listen_ports=None)
        self.add(daemon_3)

    def setup(self, old_version):
        """Install and configure the app."""
        super().setup(old_version)
        if not old_version:
            self.enable()