moltenbar/mod/memory

30 lines
583 B
Plaintext
Raw Permalink Normal View History

# vim: ft=ruby
class ModMemory < Worker
def mainloop()
while true do
mem = {}
File.read("/proc/meminfo").each_line do |line|
k, v = line.split[0..1]
mem[k] = v.to_i
end
used_part = 100 - (mem["MemAvailable:"]/(mem["MemTotal:"]/100))
if used_part > @my_config['crit_value']
fg_colour = "crit_colour"
elsif used_part > @my_config['warn_value']
fg_colour = "warn_colour"
else
fg_colour = "ok_colour"
end
self.write "%%{FC{%s}}%s%%{F-}" % [ fg_colour, used_part.to_s ]
sleep(1)
end
end
end
Modules.add("memory", "ModMemory")