Skip to content

Instantly share code, notes, and snippets.

@happymcplaksin
Created November 5, 2013 21:06
Show Gist options
  • Save happymcplaksin/7326318 to your computer and use it in GitHub Desktop.
Save happymcplaksin/7326318 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
require 'json'
host = 'graphite.example.com'
port = 2003
now = Time.now.to_i
stats = ''
# <metric path> <metric value> <metric timestamp>
JSON.load(File.open(ARGV.pop)).each do |path,data|
# carbon uses . as seperator
path = path.sub(/^\/rrd\/\//,'').gsub('//','.').sub('/','.').sub(/.rrd$/,'')
data.first.last.values.first.each do |ts,value|
stats << "#{path} #{value} #{now}\n"
end
end
# Stolen from Logstash graphite output
require "socket"
socket = TCPSocket.new(host, port)
socket.puts(stats)
socket.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment