Class: Check
Constant Summary
collapse
- RETURN_CODES =
{0 => 'ok', 1 => 'warning', 2 => 'critical'}
Instance Attribute Summary
#config
Instance Method Summary
collapse
exit_on_failure?
#cs_routers, #load_template
Instance Method Details
#cpu ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/cloudstack-nagios/commands/check.rb', line 70
def cpu
host = SSHKit::Host.new("root@#{options[:host]}")
host.ssh_options = sshoptions(options[:ssh_key])
host.port = options[:port]
mpstat_output = ""
on host do |h|
mpstat_output = capture(:mpstat)
end
values = mpstat_output.scan(/\d+/)
usage = 100 - values[-1].to_f
data = check_data(100, usage, options[:warning], options[:critical])
puts "CPU #{RETURN_CODES[data[0]]} - usage = #{data[1]}% | usage=#{data[1]}%"
exit data[0]
end
|
#memory ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/cloudstack-nagios/commands/check.rb', line 30
def memory
host = SSHKit::Host.new("root@#{options[:host]}")
host.ssh_options = sshoptions(options[:ssh_key])
host.port = options[:port]
free_output = ""
on host do |h|
free_output = capture(:free)
end
values = free_output.scan(/\d+/)
total = values[0].to_i
free = values[2].to_i
free_b = values[7].to_i
data = check_data(total, free_b, options[:warning], options[:critical])
puts "MEMORY #{RETURN_CODES[data[0]]} - usage = #{data[1]}% | usage=#{data[1]}% total=#{total}M, free=#{free}M, free_wo_buffers=#{free_b}M"
exit data[0]
end
|
#network ⇒ Object
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
# File 'lib/cloudstack-nagios/commands/check.rb', line 145
def network
host = SSHKit::Host.new("root@#{options[:host]}")
host.ssh_options = sshoptions(options[:ssh_key])
host.port = options[:port]
r1, t1, r2, t2 = ""
on host do |h|
r1 = capture(:cat, '/sys/class/net/eth0/statistics/rx_bytes').to_f
t1 = capture(:cat, '/sys/class/net/eth0/statistics/tx_bytes').to_f
sleep 1
r2 = capture(:cat, '/sys/class/net/eth0/statistics/rx_bytes').to_f
t2 = capture(:cat, '/sys/class/net/eth0/statistics/tx_bytes').to_f
end
rbps = (r2 - r1)
tbps = (t2 - t1)
data = check_data(1073741824, (1073741824 - rbps), options[:warning], options[:critical])
puts "NETWORK #{RETURN_CODES[data[0]]} - usage = #{data[1]}% | rxbps=#{rbps.round(0)}B, txbps=#{tbps.round(0)}B"
exit data[0]
end
|
#rootfs_rw ⇒ Object
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/cloudstack-nagios/commands/check.rb', line 108
def rootfs_rw
host = SSHKit::Host.new("root@#{options[:host]}")
host.ssh_options = sshoptions(options[:ssh_key])
host.port = options[:port]
proc_out = ""
on host do |h|
proc_out = capture(:cat, '/proc/mounts')
end
rootfs_rw = proc_out.match(/rootfs\srw\s/)
status = rootfs_rw ? 0 : 2
puts "ROOTFS_RW #{rootfs_rw ? 'OK - rootfs writeable' : 'CRITICAL - rootfs NOT writeable'}"
exit status
end
|