2020-03-06 14:31:29 +01:00
|
|
|
# pylint: disable=C0111,R0903
|
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
"""Displays CPU utilization across all CPUs.
|
2020-03-06 14:31:29 +01:00
|
|
|
|
2020-07-18 08:16:57 +02:00
|
|
|
By default, opens `gnome-system-monitor` on left mouse click.
|
|
|
|
|
2020-05-21 13:10:53 +02:00
|
|
|
Requirements:
|
|
|
|
* the psutil Python module for the first three items from the list above
|
2020-07-18 08:16:57 +02:00
|
|
|
* gnome-system-monitor for default mouse click action
|
2020-05-21 13:10:53 +02:00
|
|
|
|
2020-03-06 14:31:29 +01:00
|
|
|
Parameters:
|
|
|
|
* cpu.warning : Warning threshold in % of CPU usage (defaults to 70%)
|
|
|
|
* cpu.critical: Critical threshold in % of CPU usage (defaults to 80%)
|
|
|
|
* cpu.format : Format string (defaults to '{:.01f}%')
|
2020-05-03 11:15:52 +02:00
|
|
|
"""
|
2020-03-06 14:31:29 +01:00
|
|
|
|
|
|
|
import psutil
|
|
|
|
|
|
|
|
import core.module
|
|
|
|
import core.widget
|
|
|
|
import core.input
|
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
|
2020-03-06 14:31:29 +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.utilization))
|
2020-05-03 11:15:52 +02:00
|
|
|
self.widget().set("theme.minwidth", self._format.format(100.0 - 10e-20))
|
2020-03-06 14:31:29 +01:00
|
|
|
self._utilization = psutil.cpu_percent(percpu=False)
|
2020-05-03 11:15:52 +02:00
|
|
|
core.input.register(
|
|
|
|
self, button=core.input.LEFT_MOUSE, cmd="gnome-system-monitor"
|
|
|
|
)
|
2020-03-06 14:31:29 +01:00
|
|
|
|
|
|
|
@property
|
|
|
|
def _format(self):
|
2020-05-03 11:15:52 +02:00
|
|
|
return self.parameter("format", "{:.01f}%")
|
2020-03-06 14:31:29 +01:00
|
|
|
|
|
|
|
def utilization(self, _):
|
|
|
|
return self._format.format(self._utilization)
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
self._utilization = psutil.cpu_percent(percpu=False)
|
|
|
|
|
|
|
|
def state(self, _):
|
|
|
|
return self.threshold_state(self._utilization, 70, 80)
|
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
|
2020-03-06 14:31:29 +01:00
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|