Last active
February 9, 2017 17:23
-
-
Save elocnatsirt/67369e01a2db95bd01a02d05108ece66 to your computer and use it in GitHub Desktop.
Reads metrics that Flume exposes on a port and converts them into Graphite format.
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 | |
# | |
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.