Skip to content

Instantly share code, notes, and snippets.

@ewhauser
Created September 17, 2011 03:39
Show Gist options
  • Save ewhauser/1223602 to your computer and use it in GitHub Desktop.
Save ewhauser/1223602 to your computer and use it in GitHub Desktop.
Pull some metrics from flume
#!/usr/bin/env ruby
require 'rubygems'
require 'getoptlong'
require 'socket'
require 'json'
require 'timeout'
require 'open-uri'
host = "localhost"
port = 35862
node = "localhost"
def usage(port)
puts
puts "flume_monitor.rb [options]"
puts "options:"
puts " -h <hostname> connect to another host (default: localhost)"
puts " -p <port> connect to another port (default: #{port})"
puts " -n <node> logical node to check"
puts
end
opts = GetoptLong.new(
[ '--help', GetoptLong::NO_ARGUMENT ],
[ '-h', GetoptLong::OPTIONAL_ARGUMENT ],
[ '-p', GetoptLong::REQUIRED_ARGUMENT ],
[ '-n', GetoptLong::REQUIRED_ARGUMENT ]
)
opts.each do |opt, arg|
case opt
when '--help'
usage(port)
exit 0
when '-h'
host = arg
when '-p'
port = arg.to_i
when '-n'
node = arg
end
end
metrics = Hash.new(0)
Timeout::timeout(10) do
begin
url = "http://#{host}:#{port}/node/reports/#{node}"
data = open("#{url}").read
rescue
#puts "Could not connect #{host}"
exit 1
end
stats = JSON.parse(data)
metrics[:thrift_source_bytes] = stats["source.ThriftEventSource.number of bytes"]
metrics[:thrift_source_events] = stats["source.ThriftEventSource.number of events"]
metrics[:thrift_source_events_queue_free] = stats["source.ThriftEventSource.queueFree"]
metrics[:sink_errors] = stats["sink.Collector.GunzipDecorator.UnbatchingDecorator.AckChecksumChecker.InsistentAppend.appendGiveups"]
metrics[:sink_retries] = stats["sink.Collector.GunzipDecorator.UnbatchingDecorator.AckChecksumChecker.InsistentAppend.appendRetries"]
metrics[:sink_requests] = stats["sink.Collector.GunzipDecorator.UnbatchingDecorator.AckChecksumChecker.InsistentAppend.appendRequests"]
metrics[:sink_success] = stats["sink.Collector.GunzipDecorator.UnbatchingDecorator.AckChecksumChecker.InsistentAppend.appendSuccessses"]
metrics[:state] = stats["state"]
end
metrics.each do |k,v|
v = 0 if v.nil?
puts "#{k}=#{v}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment