2020-03-05 21:13:15 +01:00
|
|
|
# pylint: disable=C0111,R0903
|
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
"""Displays system load.
|
2020-03-05 21:13:15 +01:00
|
|
|
|
|
|
|
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)
|
2020-05-03 11:15:52 +02:00
|
|
|
"""
|
2020-03-05 21:13:15 +01:00
|
|
|
|
|
|
|
import os
|
|
|
|
import multiprocessing
|
|
|
|
|
|
|
|
import core.module
|
|
|
|
import core.input
|
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
|
2020-03-05 21:13:15 +01:00
|
|
|
class Module(core.module.Module):
|
2020-04-26 16:39:24 +02:00
|
|
|
def __init__(self, config, theme):
|
|
|
|
super().__init__(config, theme, core.widget.Widget(self.load))
|
2020-03-05 21:13:15 +01:00
|
|
|
self._load = [0, 0, 0]
|
|
|
|
try:
|
|
|
|
self._cpus = multiprocessing.cpu_count()
|
|
|
|
except NotImplementedError as e:
|
|
|
|
self._cpus = 1
|
2020-05-03 11:15:52 +02:00
|
|
|
core.input.register(
|
|
|
|
self, button=core.input.LEFT_MOUSE, cmd="gnome-system-monitor"
|
|
|
|
)
|
2020-03-05 21:13:15 +01:00
|
|
|
|
|
|
|
def load(self, widget):
|
2020-05-03 11:15:52 +02:00
|
|
|
return "{:.02f}/{:.02f}/{:.02f}".format(
|
2020-03-05 21:13:15 +01:00
|
|
|
self._load[0], self._load[1], self._load[2]
|
|
|
|
)
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
self._load = os.getloadavg()
|
|
|
|
|
|
|
|
def state(self, widget):
|
2020-05-03 11:15:52 +02:00
|
|
|
return self.threshold_state(self._load[0], self._cpus * 0.7, self._cpus * 0.8)
|
|
|
|
|
2020-03-05 21:13:15 +01:00
|
|
|
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|