Ruby
How to send metrics using Ruby
gem install hosted_graphite
HostedGraphite.protocol = HostedGraphite::TCP
HostedGraphite.send_metric('foo.tcp', 1.2)
HostedGraphite.protocol = HostedGraphite::UDP
HostedGraphite.send_metric('foo.udp', 1.2)
HostedGraphite.protocol = HostedGraphite::HTTP
HostedGraphite.send_metric('foo.http', 1.2)
require 'hosted_graphite'
require 'statsd-ruby'
HostedGraphite.api_key = '<your-api-key>'
HostedGraphite.protocol = :statsd
HostedGraphite.<gauge-count-or-timing>('foo.statsd', 1.2)
Here are some ways to send via TCP, UDP and HTTP directly in your code.
require 'socket'
conn = TCPSocket.new 'YOUR-UID.carbon.hostedgraphite.com', 2003
conn.puts "YOUR-API-KEY.foo 1.2\n"
conn.close
require 'socket'
sock = UDPSocket.new
sock.send "YOUR-API-KEY.foo 1.2\n", 0, "YOUR-UID.carbon.hostedgraphite.com", 2003
require 'net/http'
uri = URI("https://www.hostedgraphite.com/api/v1/sink")
api_key = "YOUR-API-KEY"
req = Net::HTTP::Post.new(uri.request_uri)
req.basic_auth api_key, nil
req.body = "foo 1.2"
res = Net::HTTP.start(uri.host, uri.port) do |http|
http.request(req)
end
Last modified 1mo ago