File: load.py

package info (click to toggle)
bumblebee-status 2.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,844 kB
  • sloc: python: 13,430; sh: 68; makefile: 29
file content (47 lines) | stat: -rw-r--r-- 1,307 bytes parent folder | download | duplicates (2)
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
# pylint: disable=C0111,R0903

"""Displays system load.

By default, opens `gnome-system-monitor` on left mouse click.

Requirements:
    * gnome-system-monitor for default mouse click action

Parameters:
    * load.warning : Warning threshold for the one-minute load average (defaults to 70% of the number of CPUs)
    * load.critical: Critical threshold for the one-minute load average (defaults to 80% of the number of CPUs)
"""

import os
import multiprocessing

import core.module
import core.input


class Module(core.module.Module):
    def __init__(self, config, theme):
        super().__init__(config, theme, core.widget.Widget(self.load))
        self._load = [0, 0, 0]
        try:
            self._cpus = multiprocessing.cpu_count()
        except NotImplementedError as e:
            self._cpus = 1

        core.input.register(
            self, button=core.input.LEFT_MOUSE, cmd="gnome-system-monitor"
        )

    def load(self, widget):
        return "{:.02f}/{:.02f}/{:.02f}".format(
            self._load[0], self._load[1], self._load[2]
        )

    def update(self):
        self._load = os.getloadavg()

    def state(self, widget):
        return self.threshold_state(self._load[0], self._cpus * 0.7, self._cpus * 0.8)


# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4