Class: Graphite::Client
- Inherits:
-
Object
- Object
- Graphite::Client
- Extended by:
- Forwardable
- Defined in:
- lib/graphite/client.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
- #find_metric(metric) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #metric_exists?(metric) ⇒ Boolean
- #reachable? ⇒ Boolean
- #render(params = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/graphite/client.rb', line 6 def initialize(={}) = {} [:ssl] = { verify: true, ca_file: File.('../cacerts.pem', __FILE__) } basic_auth = .delete(:basic_auth) @connection = Faraday.new(.merge()) if basic_auth.present? @connection.basic_auth(basic_auth[:user],basic_auth[:password]) end end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
4 5 6 |
# File 'lib/graphite/client.rb', line 4 def connection @connection end |
Instance Method Details
#find_metric(metric) ⇒ Object
21 22 23 |
# File 'lib/graphite/client.rb', line 21 def find_metric(metric) connection.get('/metrics/find',{ query: metric }) end |
#metric_exists?(metric) ⇒ Boolean
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/graphite/client.rb', line 24 def metric_exists?(metric) exists = false response = find_metric(metric) # Does this need to handle redirects? if response.status == 200 && response.headers['content-type']=='application/json' json = JSON.parse(response.body) exists = true unless json.empty? end exists end |
#reachable? ⇒ Boolean
34 35 36 37 38 39 40 41 42 |
# File 'lib/graphite/client.rb', line 34 def reachable? reachable = false begin response = connection.get('/render') reachable = response.status==200 && response.headers['content-type']=='image/png' && response.headers['content-length'].to_i > 0 rescue Exception => e end reachable end |
#render(params = {}) ⇒ Object
18 19 20 |
# File 'lib/graphite/client.rb', line 18 def render(params={}) connection.get('/render',params) end |