You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
A Ruby library for reading metrics stored on a Prometheus server.
Install
gem install prometheus-api-client
Usage
Overview
require'prometheus/api_client'# return a client for host http://localhost:9090/api/v1/prometheus=Prometheus::ApiClient.client
Changing server hostname
# return a client for host http://example.com:9090/api/v1/prometheus=Prometheus::ApiClient.client(url:'http://example.com:9090')
Authentication proxy
If an authentication proxy ( e.g. oauth2 ) is used in a layer above theprometheus REST server, this client can use ssl and authentication headears.
# return a client for host https://example.com/api/v1/ using a Bearer token "TopSecret"prometheus=Prometheus::ApiClient.client(url:'https://example.com:443',credentials:{token:'TopSecret'})
Low level calls
query
# send a low level get request to serverprometheus.get('query_range',query:'sum(container_cpu_usage_seconds_total' \'{container_name="prometheus-hgv4s",job="kubernetes-nodes"})',start:'2015-07-01T20:10:30.781Z',end:'2015-07-02T20:10:30.781Z',step:'120s',)
# response from server is a low level response struct including# fields like: method, body and request_headers# usually users will not need to use this low level calls ... method=:get, body="{\"status\":\"success\", ...
High level calls
query
# send a query request to serverprometheus.query(query:'sum(container_cpu_usage_seconds_total' \'{container_name="prometheus-hgv4s",job="kubernetes-nodes"})',time:'2015-07-01T20:10:30.781Z',)
# response from server:{"resultType"=>"vector", "result"=>[{"metric"=>{}, "value"=>[1502350741.161, "6606.310387038"]}]}
query_range
# send a query_range request to serverprometheus.query_range(query:'sum(container_cpu_usage_seconds_total' \'{container_name="prometheus-hgv4s",job="kubernetes-nodes"})',start:'2015-07-01T20:10:30.781Z',end:'2015-07-02T20:10:30.781Z',step:'120s',)