Skip to content

Instantly share code, notes, and snippets.

@elocnatsirt
Last active February 9, 2017 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elocnatsirt/f9a2954aba4b2e3eaad854efd84e391a to your computer and use it in GitHub Desktop.
Save elocnatsirt/f9a2954aba4b2e3eaad854efd84e391a to your computer and use it in GitHub Desktop.
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
Copy link
Author

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