Higher precision percents

This commit is contained in:
dave 2018-02-26 21:43:00 -08:00
parent 79d2f18330
commit 03bb7c7962
3 changed files with 11 additions and 11 deletions

View File

@ -1 +1 @@
__version__ = "0.1.4"
__version__ = "0.1.5"

View File

@ -40,11 +40,11 @@ def diskspace(filesystems=[], discover=True, omit=[]):
"inodesused": stats.f_files - stats.f_favail
}
info["diskpctused"] = round(info["diskused"] / info["disksize"] if info["disksize"] > 0 else 0, 2)
info["diskpctfree"] = round(info["diskfree"] / info["disksize"] if info["disksize"] > 0 else 0, 2)
info["diskpctused"] = round(info["diskused"] / info["disksize"] if info["disksize"] > 0 else 0, 5)
info["diskpctfree"] = round(info["diskfree"] / info["disksize"] if info["disksize"] > 0 else 0, 5)
info["inodesused_pct"] = round(info["inodesused"] / info["inodesmax"] if info["inodesmax"] > 0 else 0, 2)
info["inodesfree_pct"] = round(info["inodesfree"] / info["inodesmax"] if info["inodesmax"] > 0 else 0, 2)
info["inodesused_pct"] = round(info["inodesused"] / info["inodesmax"] if info["inodesmax"] > 0 else 0, 5)
info["inodesfree_pct"] = round(info["inodesfree"] / info["inodesmax"] if info["inodesmax"] > 0 else 0, 5)
yield info

View File

@ -3,16 +3,16 @@ import re
memline_pattern = re.compile(r'^(?P<key>[^\\:]+)\:\s+(?P<value>[0-9]+)(\s(?P<unit>[a-zA-Z]+))?')
computed_fields = {
"mempctused": lambda items: round((items["memtotal"] - items["memfree"]) / items["memtotal"], 2),
"mempctfree": lambda items: 1 - round((items["memtotal"] - items["memfree"]) / items["memtotal"], 2),
"mempctused": lambda items: round((items["memtotal"] - items["memfree"]) / items["memtotal"], 5),
"mempctfree": lambda items: 1 - round((items["memtotal"] - items["memfree"]) / items["memtotal"], 5),
"mempctused_nocache": lambda items: round((items["memtotal"] - items["memfree"] - items["cached"]) /
items["memtotal"], 2),
items["memtotal"], 5),
"mempctfree_nocache": lambda items: 1 - round((items["memtotal"] - items["memfree"] - items["cached"]) /
items["memtotal"], 2),
items["memtotal"], 5),
"swappctused": lambda items: round((items["swaptotal"] - items["swapfree"]) /
items["swaptotal"] if items["swaptotal"] > 0 else 0, 2),
items["swaptotal"] if items["swaptotal"] > 0 else 0, 5),
"swappctfree": lambda items: 1 - round((items["swaptotal"] - items["swapfree"]) /
items["swaptotal"] if items["swaptotal"] > 0 else 0, 2)
items["swaptotal"] if items["swaptotal"] > 0 else 0, 5)
}