How can I get started with Metrics on Heroku?

Metrics Heroku add-on

The Metrics Heroku add-on allows you to easily create a Metrics account for your Heroku application. This will provision an account, link it to your app, and provide instant dashboard access to any metrics you push up. The add-on is currently in alpha testing, if you would like an invite please contact metrics@librato.com. Users who already have a Metrics account (by creating one through our site) can use those credentials instead.

Username and Token

Using the add-on populates the environment with a username and API token for instant access to your account. These will be ENV["LIBRATO_METRICS_USER"] and ENV["LIBRATO_METRICS_TOKEN"]

If you do not have the add-on but would like to use a standard Metrics account, you will need to obtain your API token

Submitting Data

Once you have access credentials, uploading data points to the Metrics API is very simple. First choose a metric: either a gauge or counter. Gauges are realtime indicators which may go up or down and are a 'snapshot' of a reading. Examples of gauges are user logins per hour or the temperature outside. Counters are continually increasing and wrap around to zero on overflow. Examples of counters are total bytes sent or miles driven. After choosing, you can POST data to it via our RESTful API. An example (in Ruby) is provided below:

require 'rest-client'

# these are automatically set by the Heroku add-on
# if you already have a username and token, place them here
user = ENV["LIBRATO_METRICS_USER"]
token = ENV["LIBRATO_METRICS_TOKEN"]

metrics_api = RestClient::Resource.new 'https://metrics-api.librato.com', user, token

# place gauges (instead of counters) in a :gauges hash
metrics_api['/v1/metrics'].post :counters => {"my_sample_counter" => { :value => 12345 }}

When data is submitted, you can view the results at http://metrics.librato.com

More information

A more fully-fledged Heroku application is available here: https://gist.github.com/1266207

A full description of the Metrics API can be found on our developer site.

Knowledge Base and Helpdesk