Sha256: 46b5d439fda535a0203f15ad67fd98f68b278afcb9ad93edaae206c48ac8c77e
Contents?: true
Size: 1.31 KB
Versions: 2
Compression:
Stored size: 1.31 KB
Contents
module Graphite class Client extend Forwardable attr_reader :connection def_delegators :@connection, :get, :post def initialize(options={}) default_options = {} default_options[:ssl] = { verify: true, ca_file: File.expand_path('../cacerts.pem', __FILE__) } basic_auth = options.delete(:basic_auth) @connection = Faraday.new(default_options.merge(options)) if basic_auth.present? @connection.basic_auth(basic_auth[:user],basic_auth[:password]) end end def render(params={}) connection.get('/render',params) end def find_metric(metric) connection.get('/metrics/find',{ query: metric }) end def metric_exists?(metric) exists = false response = find_metric(metric) # Does this need to handle redirects? if response.status == 200 && response.headers['content-type'].include?('application/json') json = JSON.parse(response.body) exists = true unless json.empty? end exists end def reachable? reachable = false begin response = connection.get('/render') reachable = response.status==200 && response.headers['content-type'].include?('image/png') && response.body.length > 0 rescue Exception => e end reachable end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rearview-1.2.3-jruby | lib/graphite/client.rb |
rearview-1.2.2.rc.2-jruby | lib/graphite/client.rb |