Skip to content

Instantly share code, notes, and snippets.

@commuterjoy
Last active December 18, 2015 14:29
Show Gist options
  • Save commuterjoy/5797793 to your computer and use it in GitHub Desktop.
Save commuterjoy/5797793 to your computer and use it in GitHub Desktop.
require 'socket'
class Graphite
attr_accessor :key
def initialize(opts)
@host = opts[:host]
@port = opts[:port] || 2003
end
def log(opts)
conn = TCPSocket.new @host, @port
conn.puts "#{opts[:path]} #{opts[:value]} #{opts[:time]}\n"
conn.close
end
end
# Usage: `ruby test.rb`
require 'lib/graphite'
path = ['<private-key>', 'omniture', 'v003', 'social-fb.article:social-fb' ]
g = Graphite.new({ :host => 'carbon.hostedgraphite.com', :verbose => true })
g.log({ :path => path.join('.'), :value => 1, :time => 1371452400 })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment