30 lines
612 B
Ruby
30 lines
612 B
Ruby
# 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
|
|
|
|
avail_part = mem["MemAvailable:"]/(mem["MemTotal:"]/100)
|
|
|
|
if avail_part < @my_config['crit_value']
|
|
fg_colour = @my_config['crit_colour']
|
|
elsif avail_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, avail_part.to_s ]
|
|
|
|
sleep(1)
|
|
end
|
|
end
|
|
end
|
|
|
|
Modules.add("memory", "ModMemory")
|