From 6dcd9e6caba4b37583a64043442731ead9d3781d Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Sat, 8 Jul 2017 07:42:14 +0200 Subject: [PATCH] [module/{load|cpu}] Use the thresholds from the parameters --- bumblebee/modules/cpu.py | 4 +++- bumblebee/modules/load.py | 6 +++++- tests/modules/test_load.py | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/bumblebee/modules/cpu.py b/bumblebee/modules/cpu.py index 5f13401..5d1b99e 100644 --- a/bumblebee/modules/cpu.py +++ b/bumblebee/modules/cpu.py @@ -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 diff --git a/bumblebee/modules/load.py b/bumblebee/modules/load.py index 4d94ee1..bebc056 100644 --- a/bumblebee/modules/load.py +++ b/bumblebee/modules/load.py @@ -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 diff --git a/tests/modules/test_load.py b/tests/modules/test_load.py index e57bc2b..7000f17 100644 --- a/tests/modules/test_load.py +++ b/tests/modules/test_load.py @@ -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