Class: Router
Constant Summary
CloudstackNagios::Helper::RETURN_CODES
Instance Attribute Summary
#config
Instance Method Summary
collapse
exit_on_failure?
#check_data, #cs_routers, #exit_with_failure, #load_template
Instance Method Details
#cpu ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/cloudstack-nagios/commands/router.rb', line 26
def cpu
begin
host = systemvm_host
mpstat_output = ""
on host do |h|
mpstat_output = capture(:mpstat)
end
values = mpstat_output.scan(/\d+\.\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]
rescue => e
exit_with_failure(e)
end
end
|
#memory ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/cloudstack-nagios/commands/router.rb', line 6
def memory
begin
host = systemvm_host
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, 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]
rescue => e
exit_with_failure(e)
end
end
|
#network ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/cloudstack-nagios/commands/router.rb', line 70
def network
begin
host = systemvm_host
stats_path = "/sys/class/net/#{options[:interface]}/statistics"
rx_bytes, tx_bytes = ""
on host do |h|
rx_bytes = capture("cat #{stats_path}/rx_bytes;sleep 1;cat #{stats_path}/rx_bytes").lines.to_a
tx_bytes = capture("cat #{stats_path}/tx_bytes;sleep 1;cat #{stats_path}/tx_bytes").lines.to_a
end
rbps = (rx_bytes[1].to_i - rx_bytes[0].to_i) * 8
tbps = (tx_bytes[1].to_i - tx_bytes[0].to_i) * 8
data = check_data(options[:if_speed], rbps, options[:warning], options[:critical])
puts "NETWORK #{RETURN_CODES[data[0]]} - usage = #{data[1]}% | usage=#{data[1]}% rxbps=#{rbps.round(0)} txbps=#{tbps.round(0)}"
exit data[0]
rescue => e
exit_with_failure(e)
end
end
|
#rootfs_rw ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/cloudstack-nagios/commands/router.rb', line 44
def rootfs_rw
begin
host = systemvm_host
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
rescue => e
exit_with_failure(e)
end
end
|