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 usage():
|
|
|
|
return "memory"
|
|
|
|
|
|
|
|
def notes():
|
|
|
|
return "Warning is at 20% available RAM, Critical at 10%."
|
|
|
|
|
|
|
|
def description():
|
|
|
|
return "Shows available RAM, total amount of RAM and the percentage of available RAM."
|
|
|
|
|
2016-10-31 12:11:39 +01:00
|
|
|
class Module(bumblebee.module.Module):
|
2016-11-01 08:09:10 +01:00
|
|
|
def __init__(self, output, args):
|
2016-10-31 12:11:39 +01:00
|
|
|
super(Module, self).__init__(args)
|
|
|
|
self._mem = psutil.virtual_memory()
|
|
|
|
|
|
|
|
def data(self):
|
|
|
|
self._mem = psutil.virtual_memory()
|
|
|
|
|
|
|
|
free = self._mem.available
|
|
|
|
total = self._mem.total
|
|
|
|
|
2016-10-31 13:34:48 +01:00
|
|
|
return "{}/{} ({:05.02f}%)".format(bumblebee.util.bytefmt(self._mem.available), bumblebee.util.bytefmt(self._mem.total), 100.0 - self._mem.percent)
|
2016-10-31 12:11:39 +01:00
|
|
|
|
|
|
|
def warning(self):
|
|
|
|
return self._mem.percent < 20
|
|
|
|
|
|
|
|
def critical(self):
|
|
|
|
return self._mem.percent < 10
|
|
|
|
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|