network; memory
Signed-off-by: fbt <fbt@fleshless.org>
This commit is contained in:
parent
1e11e1422c
commit
c87fc80abb
29
mod/memory
Normal file
29
mod/memory
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
# 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")
|
14
mod/network
14
mod/network
|
@ -16,21 +16,19 @@ class Network < Worker
|
||||||
hosts = @my_config['hosts']
|
hosts = @my_config['hosts']
|
||||||
|
|
||||||
net_fail = 0
|
net_fail = 0
|
||||||
Open3.popen2("fping", *hosts) do |i,o,t|
|
Open3.popen2("fping", "-u", *hosts) do |i,o,t|
|
||||||
net_ok = o.each_line.count
|
hosts_down = o.each_line.count
|
||||||
|
hosts_up = hosts.count - hosts_down
|
||||||
|
|
||||||
if net_ok == hosts.count
|
if hosts_down == 0
|
||||||
status = "ok"
|
|
||||||
fg_colour = @my_config['ok_colour']
|
fg_colour = @my_config['ok_colour']
|
||||||
elsif net_ok == 0
|
elsif hosts_down == hosts.count
|
||||||
status = "CRIT: all hosts failed!"
|
|
||||||
fg_colour = @my_config['crit_colour']
|
fg_colour = @my_config['crit_colour']
|
||||||
else
|
else
|
||||||
status = "WARN: #{net_ok}/#{hosts.count} hosts ok"
|
|
||||||
fg_colour = @my_config['warn_colour']
|
fg_colour = @my_config['warn_colour']
|
||||||
end
|
end
|
||||||
|
|
||||||
@rstr = "%{F#{fg_colour}}#{status}%{F-}"
|
@rstr = "%%{F%s}%s/%s%%{F-}" % [ fg_colour, hosts_up, hosts.count ]
|
||||||
end
|
end
|
||||||
|
|
||||||
return @rstr
|
return @rstr
|
||||||
|
|
Loading…
Reference in New Issue
Block a user