Class: Hawkular::Prometheus::Client
- Inherits:
-
BaseClient
- Object
- BaseClient
- Hawkular::Prometheus::Client
- Defined in:
- lib/hawkular/prometheus/prometheus_api.rb
Overview
Interface to talk with the Prometheus server used for Middleware Manager
Constant Summary
Constants inherited from BaseClient
BaseClient::HawkularConnectionException, BaseClient::HawkularException
Instance Attribute Summary collapse
-
#entrypoint ⇒ Object
readonly
Returns the value of attribute entrypoint.
Attributes inherited from BaseClient
Instance Method Summary collapse
-
#initialize(entrypoint, credentials = {}, options = {}) ⇒ Client
constructor
A new instance of Client.
- #ping ⇒ Object
- #query(metrics: [], time: nil) ⇒ Object
- #query_range(metrics: [], starts: nil, ends: nil, step: nil) ⇒ Object
- #up_time(feed_id: nil, starts: nil, ends: nil, step: nil) ⇒ Object
Methods inherited from BaseClient
#admin_header, #base_64_credentials, #generate_query_params, #http_delete, #http_get, #http_post, #http_put, #normalize_entrypoint_url, #now, #url, #url_with_websocket_scheme
Methods included from ClientUtils
Constructor Details
#initialize(entrypoint, credentials = {}, options = {}) ⇒ Client
Returns a new instance of Client.
22 23 24 25 26 |
# File 'lib/hawkular/prometheus/prometheus_api.rb', line 22 def initialize(entrypoint, credentials = {}, = {}) prometheus_entrypoint = Alerter.new(entrypoint, credentials, ).prometheus_entrypoint @entrypoint = normalize_entrypoint_url prometheus_entrypoint, 'api/v1' super(@entrypoint, credentials, ) end |
Instance Attribute Details
#entrypoint ⇒ Object (readonly)
Returns the value of attribute entrypoint.
20 21 22 |
# File 'lib/hawkular/prometheus/prometheus_api.rb', line 20 def entrypoint @entrypoint end |
Instance Method Details
#ping ⇒ Object
62 63 64 |
# File 'lib/hawkular/prometheus/prometheus_api.rb', line 62 def ping http_get '/query?query=up' end |
#query(metrics: [], time: nil) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/hawkular/prometheus/prometheus_api.rb', line 28 def query(metrics: [], time: nil) results = [] metrics.each do |metric| query = metric['expression'] response = http_get "/query?start=#{time}&query=#{query}" result = response['data']['result'].empty? ? {} : response['data']['result'].first result['metric'] = metric results << result end results end |
#query_range(metrics: [], starts: nil, ends: nil, step: nil) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/hawkular/prometheus/prometheus_api.rb', line 40 def query_range(metrics: [], starts: nil, ends: nil, step: nil) results = [] metrics.each do |metric| query = metric['expression'] response = http_get "/query_range?start=#{starts}&end=#{ends}&step=#{step}&query=#{query}" result = response['data']['result'].empty? ? {} : response['data']['result'].first result['metric'] = metric results << result end results end |
#up_time(feed_id: nil, starts: nil, ends: nil, step: nil) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/hawkular/prometheus/prometheus_api.rb', line 52 def up_time(feed_id: nil, starts: nil, ends: nil, step: nil) query = "up{feed_id=\"#{feed_id}\"}" response = http_get "/query_range?start=#{starts}&end=#{ends}&step=#{step}&query=#{query}" if response['data']['result'].empty? [] else response['data']['result'].first['values'] end end |