[module/{load|cpu}] Use the thresholds from the parameters

This commit is contained in:
Frederic Junod 2017-07-08 07:42:14 +02:00
parent b22356d52b
commit 6dcd9e6cab
3 changed files with 9 additions and 3 deletions

View file

@ -21,6 +21,8 @@ class Module(bumblebee.engine.Module):
widget = bumblebee.output.Widget(full_text=self.utilization)
widget.set("theme.minwidth", "99.9%")
super(Module, self).__init__(engine, config, widget)
self._warn_threshold = float(self.parameter("warning", 70))
self._crit_threshold = float(self.parameter("critical", 80))
self._utilization = psutil.cpu_percent(percpu=False)
engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE,
cmd="gnome-system-monitor")
@ -32,6 +34,6 @@ class Module(bumblebee.engine.Module):
self._utilization = psutil.cpu_percent(percpu=False)
def state(self, _):
return self.threshold_state(self._utilization, 70, 80)
return self.threshold_state(self._utilization, self._warn_threshold, self._crit_threshold)
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

View file

@ -24,6 +24,8 @@ class Module(bumblebee.engine.Module):
self._cpus = multiprocessing.cpu_count()
except NotImplementedError as e:
self._cpus = 1
self._warn_threshold = float(self.parameter("warning", 70)) / 100
self._crit_threshold = float(self.parameter("critical", 80)) / 100
engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE,
cmd="gnome-system-monitor")
@ -36,6 +38,8 @@ class Module(bumblebee.engine.Module):
self._load = os.getloadavg()
def state(self, widget):
return self.threshold_state(self._load[0], self._cpus*0.7, self._cpus*0.8)
warn = self._cpus * self._warn_threshold
crit = self._cpus * self._crit_threshold
return self.threshold_state(self._load[0], warn, crit)
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

View file

@ -51,7 +51,7 @@ class TestLoadModule(unittest.TestCase):
def test_assume_single_core(self):
self.mp.cpu_count.side_effect = NotImplementedError
module = Module(engine=self.engine, config={"config": mock.Mock() })
module = Module(engine=self.engine, config={"config": {} })
self.assertEquals(1, module._cpus)
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4