2016-10-31 12:11:39 +01:00
|
|
|
import psutil
|
2016-10-31 13:34:48 +01:00
|
|
|
import bumblebee.module
|
|
|
|
import bumblebee.util
|
2016-10-31 12:11:39 +01:00
|
|
|
|
2016-10-31 16:08:03 +01:00
|
|
|
def description():
|
|
|
|
return "Shows available RAM, total amount of RAM and the percentage of available RAM."
|
|
|
|
|
2016-11-05 16:18:53 +01:00
|
|
|
def parameters():
|
|
|
|
return [
|
2016-11-15 20:34:14 +01:00
|
|
|
"memory.warning: Warning threshold in % of memory used (defaults to 80%)",
|
|
|
|
"memory.critical: Critical threshold in % of memory used (defaults to 90%)",
|
2016-11-05 16:18:53 +01:00
|
|
|
]
|
|
|
|
|
2016-10-31 12:11:39 +01:00
|
|
|
class Module(bumblebee.module.Module):
|
2016-12-02 18:53:34 +01:00
|
|
|
def __init__(self, output, config):
|
|
|
|
super(Module, self).__init__(output, config)
|
2016-10-31 12:11:39 +01:00
|
|
|
self._mem = psutil.virtual_memory()
|
|
|
|
|
2016-11-05 15:28:33 +01:00
|
|
|
output.add_callback(module=self.instance(), button=1, cmd="gnome-system-monitor")
|
2016-11-01 08:15:57 +01:00
|
|
|
|
2016-11-05 13:42:26 +01:00
|
|
|
def widgets(self):
|
2016-10-31 12:11:39 +01:00
|
|
|
self._mem = psutil.virtual_memory()
|
|
|
|
|
2016-11-03 19:45:48 +01:00
|
|
|
used = self._mem.total - self._mem.available
|
2016-10-31 12:11:39 +01:00
|
|
|
|
2016-11-05 13:42:26 +01:00
|
|
|
return bumblebee.output.Widget(self, "{}/{} ({:05.02f}%)".format(
|
|
|
|
bumblebee.util.bytefmt(used),
|
|
|
|
bumblebee.util.bytefmt(self._mem.total),
|
|
|
|
self._mem.percent)
|
|
|
|
)
|
2016-10-31 12:11:39 +01:00
|
|
|
|
2016-11-05 13:42:26 +01:00
|
|
|
def warning(self, widget):
|
2016-11-15 20:34:14 +01:00
|
|
|
return self._mem.percent > self._config.parameter("warning", 80)
|
2016-10-31 12:11:39 +01:00
|
|
|
|
2016-11-05 13:42:26 +01:00
|
|
|
def critical(self, widget):
|
2016-11-15 20:34:14 +01:00
|
|
|
return self._mem.percent > self._config.parameter("critical", 90)
|
2016-10-31 12:11:39 +01:00
|
|
|
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|