Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Reads metrics that Finagle exposes on a port and converts them into Graphite format.
#!/usr/bin/env ruby
#
# This script gets Finagle metrics from various applications
# Written By: https://github.com/elocnatsirt
# Options:
# -h = host that you want to query - defaults to localhost
# -p = port of the nimbus node you want to query - defaults to 9990
require 'socket'
require 'English'
require 'sensu-plugin/metric/cli'
class FinagleMetrics < 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: '9990'
option :scheme,
description: 'Metric naming scheme, text to prepend to metric',
short: '-s SCHEME',
long: '--scheme SCHEME',
required: true,
default: "#{Socket.gethostname}.finagle_metrics"
def run
cmd = "curl --silent #{config[:host]}:#{config[:port]}/admin/metrics.json?pretty=true | sed 's/[{}]//g;/^\s*$/d;s/,//;s/\"//g;s/ //g'"
metrics = `#{cmd}`
time = Time.now.to_i
metrics.each_line do |metric|
(metric_name, metric_total) = metric.split(':')
puts "#{config[:scheme]}.#{metric_name} #{metric_total.chomp} #{time}"
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

I wrote this to get finagle metrics from our various applications that expose them. The metrics are read from a page that displays them in a JSON structure and just has basic key/value pairs and transforms them into the graphite format. In theory you could use this for any anything that outputs data in that basic format; however it will not handle any nested structures inside the main one.

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