added 2 warning states, color support, support for user defined devisor, configurable rounding of byte values for mem module and fixed used memory calculation in mem module
This commit is contained in:
parent
5fc8ed3f8e
commit
165049862b
@ -1,8 +1,6 @@
|
||||
from i3pystatus import IntervalModule
|
||||
from psutil import virtual_memory
|
||||
|
||||
MEGABYTE = 1024 * 1024
|
||||
|
||||
|
||||
class Mem(IntervalModule):
|
||||
"""
|
||||
@ -18,19 +16,49 @@ class Mem(IntervalModule):
|
||||
Requires psutil (from PyPI)
|
||||
"""
|
||||
|
||||
format = "{avail_mem} MB"
|
||||
format = "{avail_mem} GB"
|
||||
divisor = 1024 ** 3
|
||||
color = "#00FF00"
|
||||
warn_color = "#FFFF00"
|
||||
alert_color = "#FF0000"
|
||||
warn_percantage = 50
|
||||
alert_percentage = 80
|
||||
_round = 2
|
||||
|
||||
settings = (
|
||||
("format", "format string used for output."),
|
||||
("divisor",
|
||||
"divide all byte values by this value, default 1024**2(mebibytes"),
|
||||
("warn_percantage", "minimal percantage for warn state"),
|
||||
("alert_percentage", "minimal percantage for alert state"),
|
||||
("color", "standard color"),
|
||||
("warn_color",
|
||||
"defines the color used wann warn percentage ist exceeded"),
|
||||
("alert_color",
|
||||
"defines the color used when alert percentage is exceeded"),
|
||||
("round", "round byte values to given length behind dot")
|
||||
|
||||
)
|
||||
|
||||
def run(self):
|
||||
vm = virtual_memory()
|
||||
# This follows the same algorithm used for vm-percent
|
||||
used = vm.used - vm.cached
|
||||
memory_usage = virtual_memory()
|
||||
used = memory_usage.used - memory_usage.cached - memory_usage.buffers
|
||||
|
||||
if memory_usage.percent >= self.alert_percentage:
|
||||
color = self.alert_color
|
||||
|
||||
elif memory_usage.percent >= self.warn_percantage:
|
||||
color = self.warn_color
|
||||
|
||||
else:
|
||||
color = self.color
|
||||
|
||||
self.output = {
|
||||
"full_text": self.format.format(
|
||||
used_mem=int(round(used / MEGABYTE, 0)),
|
||||
avail_mem=int(round(vm.available / MEGABYTE, 0)),
|
||||
total_mem=int(round(vm.total / MEGABYTE, 0)),
|
||||
percent_used_mem=vm.percent)
|
||||
used_mem=round(used / self.divisor, self._round),
|
||||
avail_mem=round(memory_usage.available / self.divisor,
|
||||
self._round),
|
||||
total_mem=round(memory_usage.total / self.divisor, self._round),
|
||||
percent_used_mem=int(memory_usage.percent)),
|
||||
"color":color
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user