Created
May 16, 2014 13:59
-
-
Save akleiber/d813d4614cb153aeafa9 to your computer and use it in GitHub Desktop.
This file contains 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
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 |
Author
akleiber
commented
May 16, 2014
- 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