Created
October 5, 2011 00:19
-
-
Save wickedchicken/1263236 to your computer and use it in GitHub Desktop.
Sample code to submit data to Librato Metrics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# example code to submit data to the Librato Metrics API | |
# for more info visit http://dev.librato.com/ | |
require 'rubygems' | |
require 'rest-client' | |
require 'json' | |
# 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 'http://metrics-api.heroku.com', user, token | |
# create a counter | |
# this should only be done once, we are creating a gem to implement find_or_create | |
# if you'd like to create a gauge instead, replace 'counters.json' with 'gauges.json' | |
counter_resp = metrics_api['/v1/counters.json'].post :name => "sample",:description => "this is a sample counter" | |
counter = counter_resp.headers[:location] # get the location of the new counter | |
# send some data to the counter | |
metrics_api[counter].post :value => 12345 | |
# if we want to inspect data we just sent | |
recv_data = metrics_api[counter].get :params => {:count => 1, :resolution => 1} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment