Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Reads metrics that Flume exposes on a port and converts them into Graphite format.
#!/usr/bin/env ruby
#
# This script queries flume to get metrics and pipes them into graphite format
# Written By: https://github.com/elocnatsirt
# Options:
# -h = host that you want to query - defaults to localhost
# -p = port of the flume node you want to query - defaults to 41414
require 'socket'
require 'English'
require 'sensu-plugin/metric/cli'
class FlumeMetrics < Sensu::Plugin::Metric::CLI::Graphite
option :host,
short: '-h URL',
long: '--host URL',
description: 'valid url to connect',
default: 'localhost'
option :port,
short: '-p PORT',
long: '--port PORT',
description: 'port to connect',
default: '41414'
option :scheme,
description: 'Metric naming scheme, text to prepend to metric',
short: '-s SCHEME',
long: '--scheme SCHEME',
required: true,
default: "#{Socket.gethostname}.flume_metrics"
def run
get_keys = "curl --silent #{config[:host]}:#{config[:port]}/metrics | jq 'keys' | jq .[] | sed 's/\"//g'"
keys = `#{get_keys}`
time = Time.now.to_i
keys.each_line do |key|
get_metrics = "curl --silent #{config[:host]}:#{config[:port]}/metrics | jq '.\"#{key.chomp}\"' | sed 's/[{}]//g;/^\s*$/d;s/,//;s/\"//g;s/ //g'"
metrics = `#{get_metrics}`
metrics.each_line do |metric|
(metric_name, metric_total) = metric.split(':')
puts "#{config[:scheme]}.#{key.chomp}.#{metric_name} #{metric_total.chomp} #{time}"
end
end
if $CHILD_STATUS.to_i == 0
ok
else
warning
end
end
end
@elocnatsirt

This comment has been minimized.

Copy link
Owner Author

@elocnatsirt elocnatsirt commented Sep 17, 2016

This will get metrics from the Apache Flume application on whatever port you are exposing them on. This assumes that you have JQ installed on the system that is running it. It looks at the top level keys and drills down further in order to get the lower level key/value pairs. In theory you could use this for any other data that follows that structure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment