Created
November 5, 2013 21:06
-
-
Save happymcplaksin/7326318 to your computer and use it in GitHub Desktop.
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/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