Add display and critical limit in the disk module

This commit is contained in:
Stéphane Brunner 2014-04-09 18:40:59 +02:00
parent d0a38e036c
commit 1f80fb4e19

View File

@ -16,18 +16,30 @@ class Disk(IntervalModule):
settings = (
"format", "path",
("divisor", "divide all byte values by this value, commonly 1024**3 (gigabyte)"),
("display_limit", "limit upper witch one the module isn't display"),
("critical_limit", "limit under witch one the disk space is critical"),
("critical_color", "the critical color"),
)
required = ("path",)
color = "#FFFFFF"
critical_color = "#FF0000"
format = "{free}/{avail}"
divisor = 1024 ** 3
display_limit = float('Inf')
critical_limit = 0
def run(self):
stat = os.statvfs(self.path)
available = (stat.f_bsize * stat.f_bavail) / self.divisor
if available > self.display_limit:
self.output = {}
return
cdict = {
"total": (stat.f_bsize * stat.f_blocks) / self.divisor,
"free": (stat.f_bsize * stat.f_bfree) / self.divisor,
"avail": (stat.f_bsize * stat.f_bavail) / self.divisor,
"avail": available,
"used": (stat.f_bsize * (stat.f_blocks - stat.f_bfree)) / self.divisor,
"percentage_free": stat.f_bfree / stat.f_blocks * 100,
"percentage_avail": stat.f_bavail / stat.f_blocks * 100,
@ -37,5 +49,6 @@ class Disk(IntervalModule):
self.output = {
"full_text": self.format.format(**cdict),
"color": self.color
"color": self.color if available > self.critical_limit else self.critical_color,
"urgent": available > self.critical_limit
}