2017-05-30 12:08:45 +00:00
|
|
|
# vim: ft=ruby
|
|
|
|
|
|
|
|
class ModMemory < Worker
|
|
|
|
def mainloop()
|
|
|
|
while true do
|
|
|
|
mem = {}
|
2018-12-01 21:19:23 +00:00
|
|
|
File.read("/proc/meminfo").each_line do |line|
|
|
|
|
k, v = line.split[0..1]
|
2018-12-01 20:14:10 +00:00
|
|
|
mem[k] = v.to_i
|
2017-05-30 12:08:45 +00:00
|
|
|
end
|
|
|
|
|
2018-12-08 09:11:45 +00:00
|
|
|
used_part = 100 - (mem["MemAvailable:"]/(mem["MemTotal:"]/100))
|
2017-05-30 12:08:45 +00:00
|
|
|
|
2019-05-15 08:50:16 +00:00
|
|
|
if used_part > @my_config['crit_value']
|
2017-05-30 12:08:45 +00:00
|
|
|
fg_colour = @my_config['crit_colour']
|
2019-05-15 08:50:16 +00:00
|
|
|
elsif used_part > @my_config['warn_value']
|
2017-05-30 12:08:45 +00:00
|
|
|
fg_colour = @my_config['warn_colour']
|
|
|
|
else
|
|
|
|
fg_colour = @my_config['ok_colour']
|
|
|
|
end
|
|
|
|
|
2018-12-08 09:11:45 +00:00
|
|
|
self.write "%%{F%s}%s%%{F-}" % [ fg_colour, used_part.to_s ]
|
2017-05-30 12:08:45 +00:00
|
|
|
|
|
|
|
sleep(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Modules.add("memory", "ModMemory")
|