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