#!/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