Created
January 5, 2012 17:04
-
-
Save netshade/1566141 to your computer and use it in GitHub Desktop.
metrics from stdin to instrumental
This file contains hidden or 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 | |
# Provide data over STDIN to Instrumental | |
# Format of data: | |
# <metric name> <value> <unix timestamp> | |
# or | |
# <metric name> <value> | |
# | |
# Second form will assume that the time the | |
# metric is reported is when the event occurred. | |
# | |
# All data is .gauge'd | |
# | |
require 'rubygems' | |
begin | |
gem 'instrumental_agent' | |
rescue Gem::LoadError | |
puts "Requires the Instrumental Agent gem:\n" | |
puts ' gem install instrumental_agent' | |
exit 1 | |
end | |
require 'instrumental_agent' | |
api_key = ENV['INSTRUMENTAL_TOKEN'] | |
unless api_key | |
puts "Requires a token:\n" | |
puts ' input | INSTRUMENTAL_TOKEN=<your API key> ./stats_to_agent' | |
exit 1 | |
end | |
collector = ENV['COLLECTOR'] || 'instrumentalapp.com:8000' | |
unless collector =~ /:\d+$/ | |
puts "Must provide a port when defining collector:\n" | |
puts ' input | INSTRUMENTAL_TOKEN=<your API key> COLLECTOR=localhost:8000 ./stats_to_agent' | |
exit 1 | |
end | |
I = Instrumental::Agent.new(api_key, :collector => collector) | |
I.synchronous = true | |
puts "Sending metrics to collector at #{collector}" | |
input = ARGF.read | |
input.each_line do |line| | |
metric, value, unix_ts = line.split(' ') | |
unix_ts ||= Time.now.to_i | |
I.gauge(metric, value, unix_ts) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment