Build Status Code Climate

HostedGraphite

A Ruby client for HostedGraphite

Installation

Add this line to your application's Gemfile:

gem 'hosted_graphite'

And then execute:

$ bundle

Or install it yourself as:

$ gem install hosted_graphite

Usage

Set ENV['HOSTEDGRAPHITE_APIKEY'] to your hosted graphite API key. Your API key can be found on your account home page.

You can also set the hosted graphite API key programatically with:

HostedGraphite.api_key = 'YOUR API KEY'

You may also specify a namespace for your metrics, which will be applied if you are using the StatsD backend:

HostedGraphite.namespace = 'our_app'

Sending a metric via UDP

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

Sending a metric via TCP

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

Sending a metric via HTTP

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

HostedStatsD

Enable Statsd on your account

Ensure these line are present in your application's Gemfile:

gem 'hosted_graphite'
gem 'statsd-ruby'

Basic usage

HostedGraphite.protocol = :statsd
# Send some stats
HostedGraphite.increment 'page_views'
HostedGraphite.decrement 'likes_count'
HostedGraphite.timing 'foo', 320
HostedGraphite.gauge 'bar', 100

# Use {#time} to time the execution of a block
HostedGraphite.time('newsletter.monthly') { @newsletter.deliver_now }

Extensions

Sidekiq

require 'hosted_graphite/ext/sidekiq'

Sidekiq.configure_server do |config|
  config.server_middleware do |chain|
    # my_app is an optional namespace
    # chain.prepend HostedGraphite::Ext::Sidekiq::StatsdMetrics, 'my_app'
    # or
    # chain.prepend HostedGraphite::Ext::Sidekiq::Metrics
  end
end

Disable sends for local/test environments

HostedGraphite.enabled = false unless Rails.env.production?

Contributing

  1. Fork it ( https://github.com/seuros/hosted_graphite/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request