Skip to content

Instantly share code, notes, and snippets.

@akleiber
Created May 16, 2014 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akleiber/d813d4614cb153aeafa9 to your computer and use it in GitHub Desktop.
Save akleiber/d813d4614cb153aeafa9 to your computer and use it in GitHub Desktop.
require 'rest-client'
require 'JSON'
require 'date'
require 'uri'
class Graphite
def initialize(host)
@host = host
end
def get_value(datapoint)
value = datapoint[0] || 0
return value.round(2)
end
def query(target, from='-2min')
target = [
target,
]
params = {:format => 'json', :from => from, :target => target}
url = URI::HTTP.build(:host => @host, :path => '/render', :query => URI.encode_www_form(params))
response = RestClient.get url.to_s
result = JSON.parse(response.body, :symbolize_names => true)
return result
end
def series(name, since='-2min')
return query(name, since).to_json
end
end
@akleiber
Copy link
Author

  • create url with URI
  • return series of data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment