class Hawkular::Prometheus::Client
Interface to talk with the Prometheus
server used for Middleware Manager @param entrypoint [String] base url of Hawkular
Services
Attributes
entrypoint[R]
Public Class Methods
new(entrypoint, credentials = {}, options = {})
click to toggle source
Calls superclass method
Hawkular::BaseClient::new
# File lib/hawkular/prometheus/prometheus_api.rb 22 def initialize(entrypoint, credentials = {}, options = {}) 23 prometheus_entrypoint = Alerter.new(entrypoint, credentials, options).prometheus_entrypoint 24 @entrypoint = normalize_entrypoint_url prometheus_entrypoint, 'api/v1' 25 super(@entrypoint, credentials, options) 26 end
Public Instance Methods
ping()
click to toggle source
# File lib/hawkular/prometheus/prometheus_api.rb 62 def ping 63 http_get '/query?query=up' 64 end
query(metrics: [], time: nil)
click to toggle source
# File lib/hawkular/prometheus/prometheus_api.rb 28 def query(metrics: [], time: nil) 29 results = [] 30 metrics.each do |metric| 31 query = metric['expression'] 32 response = http_get "/query?start=#{time}&query=#{query}" 33 result = response['data']['result'].empty? ? {} : response['data']['result'].first 34 result['metric'] = metric 35 results << result 36 end 37 results 38 end
query_range(metrics: [], starts: nil, ends: nil, step: nil)
click to toggle source
# File lib/hawkular/prometheus/prometheus_api.rb 40 def query_range(metrics: [], starts: nil, ends: nil, step: nil) 41 results = [] 42 metrics.each do |metric| 43 query = metric['expression'] 44 response = http_get "/query_range?start=#{starts}&end=#{ends}&step=#{step}&query=#{query}" 45 result = response['data']['result'].empty? ? {} : response['data']['result'].first 46 result['metric'] = metric 47 results << result 48 end 49 results 50 end
up_time(feed_id: nil, starts: nil, ends: nil, step: nil)
click to toggle source
# File lib/hawkular/prometheus/prometheus_api.rb 52 def up_time(feed_id: nil, starts: nil, ends: nil, step: nil) 53 query = "up{feed_id=\"#{feed_id}\"}" 54 response = http_get "/query_range?start=#{starts}&end=#{ends}&step=#{step}&query=#{query}" 55 if response['data']['result'].empty? 56 [] 57 else 58 response['data']['result'].first['values'] 59 end 60 end