Improved handling of (un)mounted drives/partitions.
richese provided base for new options.
This commit is contained in:
parent
87c01278f7
commit
1c4f941304
@ -13,25 +13,43 @@ class Disk(IntervalModule):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
settings = (
|
settings = (
|
||||||
"format", "path",
|
"format",
|
||||||
|
"path",
|
||||||
("divisor", "divide all byte values by this value, default is 1024**3 (gigabyte)"),
|
("divisor", "divide all byte values by this value, default is 1024**3 (gigabyte)"),
|
||||||
("display_limit", "if more space is available than this limit the module is hidden"),
|
("display_limit", "if more space is available than this limit the module is hidden"),
|
||||||
("critical_limit", "critical space limit (see critical_color)"),
|
("critical_limit", "critical space limit (see critical_color)"),
|
||||||
("critical_color", "the critical color"),
|
("critical_color", "the critical color"),
|
||||||
("color", "the common color"),
|
("color", "the common color"),
|
||||||
("round_size", "precision, None for INT"),
|
("round_size", "precision, None for INT"),
|
||||||
|
("mounted_only", "display only if path is a valid mountpoint"),
|
||||||
|
"format_not_mounted",
|
||||||
|
"color_not_mounted"
|
||||||
)
|
)
|
||||||
required = ("path",)
|
required = ("path",)
|
||||||
color = "#FFFFFF"
|
color = "#FFFFFF"
|
||||||
|
color_not_mounted = "#FFFFFF"
|
||||||
critical_color = "#FF0000"
|
critical_color = "#FF0000"
|
||||||
format = "{free}/{avail}"
|
format = "{free}/{avail}"
|
||||||
|
format_not_mounted = None
|
||||||
divisor = 1024 ** 3
|
divisor = 1024 ** 3
|
||||||
display_limit = float('Inf')
|
display_limit = float('Inf')
|
||||||
critical_limit = 0
|
critical_limit = 0
|
||||||
round_size = 2
|
round_size = 2
|
||||||
|
mounted_only = False
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
try:
|
||||||
stat = os.statvfs(self.path)
|
stat = os.statvfs(self.path)
|
||||||
|
except Exception:
|
||||||
|
if self.mounted_only:
|
||||||
|
self.output = {}
|
||||||
|
else:
|
||||||
|
self.output = {} if not self.format_not_mounted else {
|
||||||
|
"full_text": self.format_not_mounted,
|
||||||
|
"color": self.color_not_mounted,
|
||||||
|
}
|
||||||
|
return
|
||||||
|
|
||||||
available = (stat.f_bsize * stat.f_bavail) / self.divisor
|
available = (stat.f_bsize * stat.f_bavail) / self.divisor
|
||||||
|
|
||||||
if available > self.display_limit:
|
if available > self.display_limit:
|
||||||
|
Loading…
Reference in New Issue
Block a user