Ruby

How to send metrics using Ruby

Installing the Ruby Gem

A Hosted Graphite Ruby Gem is available on github, and can be installed directly by typing:

gem install hosted_graphite

Using the Gem to send via TCP

HostedGraphite.protocol = HostedGraphite::TCP
HostedGraphite.send_metric('foo.rb-tcp', 1.2)

Using the Gem to send via UDP

HostedGraphite.protocol = HostedGraphite::UDP
HostedGraphite.send_metric('foo.rb-udp', 1.2)

Using the Gem to send via HTTP

HostedGraphite.protocol = HostedGraphite::HTTP
HostedGraphite.send_metric('foo.rb-http', 1.2)

Using the Gem to send via StatsD

require 'hosted_graphite'
require 'statsd-ruby'

HostedGraphite.api_key = '<your-api-key>'
HostedGraphite.protocol = :statsd
HostedGraphite.<gauge-count-or-timing>('foo.rb-statsd', 1.2)

Basic Ruby

Here are some ways to send custom metric via TCP, UDP, HTTP, and StatsD directly from your code.

Sending a metric via TCP

Sending a metric via UDP

Sending a metric via HTTP POST

Sending a metric via StatsD

NOTE: when sending standard ruby StatsD metrics, be sure to define counters (c), gauges (g), or timers (ms).

Your API key can be found on your account home page.

Last updated

Was this helpful?