30 lines
692 B
Ruby
30 lines
692 B
Ruby
# vim: ft=ruby
|
|
|
|
class ModMemory < Worker
|
|
def mainloop()
|
|
while true do
|
|
mem = {}
|
|
data = File.read("/proc/meminfo").scan(/Mem(Total|Available):\s+([0-9]+)/).map do |k, v|
|
|
mem[k] = v
|
|
end
|
|
|
|
mem["free_part"] = mem["Available"].to_i/(mem["Total"].to_i/100)
|
|
mem["used_part"] = 100 - mem["free_part"]
|
|
|
|
if mem["used_part"] > @my_config['crit_value']
|
|
fg_colour = @my_config['crit_colour']
|
|
elsif mem["used_part"] > @my_config['warn_value']
|
|
fg_colour = @my_config['warn_colour']
|
|
else
|
|
fg_colour = @my_config['ok_colour']
|
|
end
|
|
|
|
self.write "%%{F%s}%s%%{F-}" % [ fg_colour, mem["used_part"].to_s ]
|
|
|
|
sleep(1)
|
|
end
|
|
end
|
|
end
|
|
|
|
Modules.add("memory", "ModMemory")
|