Created
October 29, 2012 22:32
-
-
Save k9ert/3976972 to your computer and use it in GitHub Desktop.
a ruby-script working as a check_mk-plugin to monitor zookeeper, place it in /usr/lib/check_mk_agent/local
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ./zkmon.rb | |
0 zk_version - OK 3.4.3-1240972, built on 02/06/2012 10:48 GMT | |
0 zk_avg_latency count=5 OK 5 | |
0 zk_max_latency count=265 OK 265 | |
0 zk_min_latency count=0 OK 0 | |
0 zk_packets_received count=2158687 OK 2158687 | |
0 zk_packets_sent count=2319327 OK 2319327 | |
0 zk_outstanding_requests count=0 OK 0 | |
0 zk_server_state - OK standalone | |
0 zk_znode_count count=10078 OK 10078 | |
0 zk_watch_count count=0 OK 0 | |
0 zk_ephemerals_count count=18 OK 18 | |
0 zk_approximate_data_size count=10268580 OK 10268580 | |
0 zk_open_file_descriptor_count count=53 OK 53 | |
0 zk_max_file_descriptor_count count=1024 OK 1024 | |
$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
server = "localhost" | |
port = "2181" | |
fields=["zk_server_state","zk_version", "zk_avg_latency", "zk_max_latency", "zk_min_latency", "zk_packets_received", "zk_packets_sent", "zk_outstanding_requests", "zk_znode_count", "zk_watch_count", "zk_ephemerals_count", "zk_approximate_data_size", "zk_open_file_descriptor_count", "zk_max_file_descriptor_count"] | |
# First: Health check | |
health=`echo "ruok" | nc #{server} 2181` | |
if !health.match(/imok/) | |
fields.each {|key| | |
print "2 #{key} - CRITICAL not imok\n" | |
} | |
exit | |
end | |
# max percentage for zk_open_file_descriptor_count | |
mpzk_open_file=0.6 | |
mon=`echo "mntr" | nc #{server} 2181` | |
mhash=Hash[*mon.split(/\n/).collect { |line| | |
[line.split(/\t/)[0], line.split(/\t/,2)[1]] | |
}.flatten] | |
# first try to get Criticals (including count) | |
fdcount=mhash["zk_open_file_descriptor_count"].to_i | |
max_fdcount=mhash["zk_max_file_descriptor_count"].to_i | |
mhash["zk_open_file_descriptor_count"] = fdcount > max_fdcount * mpzk_open_file ? "count="+ fdcount.to_s + " CRITICAL " + fdcount.to_s : "count="+ fdcount.to_s + " OK " + fdcount.to_s | |
fields.delete("zk_open_file_descriptor_count") | |
# keys not returning numbers | |
["zk_server_state","zk_version"].each {|key| | |
mhash[key]=" - OK "+mhash[key].to_s | |
} | |
fields.delete("zk_server_state") | |
fields.delete("zk_version") | |
# insert count= to the rest | |
fields.each {|thekey| | |
mhash[thekey]="count=" + mhash[thekey].to_s + " OK " + mhash[thekey].to_s | |
} | |
# now let's dump it | |
mhash.each_key do |key| | |
if mhash[key].match(" OK ") | |
rtvalue = 0 | |
end | |
if mhash[key].match(" WARNING ") | |
rtvalue = 1 | |
end | |
if mhash[key].match(" CRITICAL ") | |
rtvalue = 2 | |
end | |
print "#{rtvalue} #{key} #{mhash[key]}\n" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Unfortunately, ruby is not an appropriate language to base check_mk plugins upon. The check needs to be really on a good performance in order to leverage the performance-advantages of check_mk.