zookeeper_info/zookeeper_info.rb
# Run the 4-letter command to grab the server stats from the running service
#
# This is what the output of the command in bash looks like:
# bash$ echo srvr | nc localhost 2181
#
# Zookeeper version: 3.3.3-cdh3u0--1, built on 03/26/2011 00:21 GMT
# Latency min/avg/max: 0/0/0
# Received: 68
# Sent: 67
# Outstanding: 0
# Zxid: 0x400000002
# Mode: follower
# Node count: 4
Run the 4-letter command to grab the server stats from the running service
This is what the output of the command in bash looks like:
bash$ echo srvr | nc localhost 2181


Run the 4 - letter command to grab the server stats from the running service This is what the output of the command in bash looks like : bash$ echo srvr | nc localhost 2181
def build_report
    lat_min, lat_avg, lat_max, received, sent, outstanding, node_count, mode = nil
    begin
      socket = TCPSocket.open("localhost", "#{option(:port)}")   
      socket.print("srvr")
      stats = socket.read
      stats.each_line do |line|
        lat_min, lat_avg, lat_max = $1, $2, $3 if line =~ /^Latency min\/avg\/max:\s+(\d+)+\/+(\d+)+\/+(\d+)/
        received = $1 if line =~ /^Received:\s+(\d+)/
        sent = $1 if line =~ /^Sent:\s+(\d+)/
        outstanding = $1 if line =~ /^Outstanding:\s+(\d+)/
        node_count = $1 if line =~ /^Node count:\s+(\d+)/
        mode = $1 if line =~ /^Mode:\s+(\w+)/
      end
      counter(:received, received.to_i,  :per => :minute)
      counter(:sent,     sent.to_i,      :per => :minute)
      report({:lat_min => lat_min, :lat_avg => lat_avg, :lat_max => lat_max, 
        :outstanding => outstanding, :node_count => node_count, :mode => mode }) 
    rescue Errno::ECONNREFUSED => e
      error(:subject => 'Unable to connect to zookeeper', :body => "The zookeeper service is not running on the specified port (#{option(:port)}).\nFull error is:\n" + e)
    end
  end
def build_report lat_min , lat_avg , lat_max , received , sent , outstanding , node_count , mode = nil begin socket = TCPSocket . open ( "localhost" , "#{option(:port)}" ) socket . print ( "srvr" ) stats = socket . read stats . each_line do | line | lat_min , lat_avg , lat_max = $1 , $2 , $3 if line =~ / ^Latency min \/ avg \/ max: \s +( \d +)+ \/ +( \d +)+ \/ +( \d +) / received = $1 if line =~ / ^Received: \s +( \d +) / sent = $1 if line =~ / ^Sent: \s +( \d +) / outstanding = $1 if line =~ / ^Outstanding: \s +( \d +) / node_count = $1 if line =~ / ^Node count: \s +( \d +) / mode = $1 if line =~ / ^Mode: \s +( \w +) / end counter ( :received , received . to_i , :per => :minute ) counter ( :sent , sent . to_i , :per => :minute ) report ( { :lat_min => lat_min , :lat_avg => lat_avg , :lat_max => lat_max , :outstanding => outstanding , :node_count => node_count , :mode => mode } ) rescue Errno :: ECONNREFUSED => e error ( :subject => 'Unable to connect to zookeeper' , :body => "The zookeeper service is not running on the specified port (#{option(:port)}).\nFull error is:\n" + e ) end end
Run the 4-letter command to grab the server stats from the running service
This is what the output of the command in bash looks like:
bash$ echo srvr | nc localhost 2181
Run the 4 - letter command to grab the server stats from the running service This is what the output of the command in bash looks like : bash$ echo srvr | nc localhost 2181
# Zero out all the variables we want to return # Ruby's error handling is weird, but this catches in the event that the port is incorrect, unresponsive # Ruby sockets! http://www.ruby-doc.org/stdlib/libdoc/socket/rdoc/index.html # Let's set the variables to the outputs, based on regexes # This line is smarter, thanks to Dan's regex-fu # Build the output report