prometheus/prometheus_api_client_ruby

Name: prometheus_api_client_ruby

Owner: Prometheus

Description: A Ruby library for reading metrics stored on a Prometheus server

Created: 2017-07-23 15:28:20.0

Updated: 2018-03-19 09:47:51.0

Pushed: 2018-02-06 14:11:03.0

Homepage:

Size: 68

Language: Ruby

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Prometheus API Ruby Client

Gem Version Build Status Build Status Coverage Status

A Ruby library for reading metrics stored on a Prometheus server.

Install
install prometheus-api-client
Usage
Overview
ire 'prometheus/api_client'

turn a client for host http://localhost:9090/api/v1/
etheus = Prometheus::ApiClient.client
Changing server hostname
turn a client for host http://example.com:9090/api/v1/
etheus = Prometheus::ApiClient.client(url: 'http://example.com:9090')
Authentication proxy

If an authentication proxy ( e.g. oauth2 ) is used in a layer above the prometheus REST server, this client can use ssl and authentication headears.

turn a client for host https://example.com/api/v1/ using a Bearer token "TopSecret"
etheus = Prometheus::ApiClient.client(url:         'https://example.com:443',
                                      credentials: { token: 'TopSecret' })
Low lavel calls query
nd a low level get request to server
etheus.get(
uery_range',
ery: 'sum(container_cpu_usage_seconds_total' \
     '{container_name="prometheus-hgv4s",job="kubernetes-nodes"})',
art: '2015-07-01T20:10:30.781Z',
d:   '2015-07-02T20:10:30.781Z',
ep:  '120s',

sponse from server is a low level response struct including
elds like: method, body and request_headers
ually users will not need to use this law level calls
..
ethod=:get,
ody="{\"status\":\"success\",
..
High level calls query
nd a query request to server
etheus.query(
ery: 'sum(container_cpu_usage_seconds_total' \
     '{container_name="prometheus-hgv4s",job="kubernetes-nodes"})',
me:  '2015-07-01T20:10:30.781Z',

sponse from server:
sultType"=>"vector", "result"=>[{"metric"=>{}, "value"=>[1502350741.161, "6606.310387038"]}]}
query_range
nd a query_range request to server
etheus.query_range(
ery: 'sum(container_cpu_usage_seconds_total' \
     '{container_name="prometheus-hgv4s",job="kubernetes-nodes"})',
art: '2015-07-01T20:10:30.781Z',
d:   '2015-07-02T20:10:30.781Z',
ep:  '120s',

sponse from server:
sultType"=>"matrix",
sult"=>
"metric"=>
 {"__name__"=>"container_cpu_usage_seconds_total",
  "beta_kubernetes_io_arch"=>"amd64",
  "beta_kubernetes_io_os"=>"linux",
  "cpu"=>"cpu00",
  "id"=>"/",
  "instance"=>"example.com",
  "job"=>"kubernetes-cadvisor",
  "kubernetes_io_hostname"=>"example.com",
  "region"=>"infra",
  "zone"=>"default"},
"values"=>[[1502086230.781, "51264.830099022"],
           [1502086470.781, "51277.367732154"]]},
"metric"=>
 {"__name__"=>"container_cpu_usage_seconds_total",
  "beta_kubernetes_io_arch"=>"amd64",
  "beta_kubernetes_io_os"=>"linux",
  "cpu"=>"cpu01",
  "id"=>"/",
  "instance"=>"example.com",
  "job"=>"kubernetes-cadvisor",
  "kubernetes_io_hostname"=>"example.com",
  "region"=>"infra",
  "zone"=>"default"},
"values"=>[[1502086230.781, "53879.644934689"],
           [1502086470.781, "53892.665282065"]]}]}
label
nd a label request to server
etheus.label('__name__')
sponse from server:
IServiceRegistrationController_adds",
IServiceRegistrationController_depth",

targets
nd a targets request to server
etheus.targets()
sponse from server:
tiveTargets"=>
"discoveredLabels"=>
 {"__address__"=>"10.35.19.248:8443",
  "__meta_kubernetes_endpoint_port_name"=>"https",
  "__meta_kubernetes_endpoint_port_protocol"=>"TCP",
  "__meta_kubernetes_endpoint_ready"=>"true",
  "__meta_kubernetes_endpoints_name"=>"kubernetes",
  "__meta_kubernetes_namespace"=>"default",
  "__meta_kubernetes_service_label_component"=>"apiserver",
  "__meta_kubernetes_service_label_provider"=>"kubernetes",
  "__meta_kubernetes_service_name"=>"kubernetes",
  "__metrics_path__"=>"/metrics",
  "__scheme__"=>"https",
  "job"=>"kubernetes-apiservers"},
"labels"=>{"instance"=>"10.35.19.248:8443", "job"=>"kubernetes-apiservers"},
"scrapeUrl"=>"https://10.35.19.248:8443/metrics",
"lastError"=>"",
"lastScrape"=>"2017-08-10T07:35:40.919376413Z",
"health"=>"up"},
...
Tests

Install necessary development gems with bundle install and run tests with rspec:



This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.