Git Product home page Git Product logo

prometheus_api_client_ruby's Introduction

Prometheus API Ruby Client

Gem Version Build Status Build Status Coverage Status

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 the prometheus 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 server
prometheus.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 law level calls
   ...
   method=:get,
   body="{\"status\":\"success\",
   ...

High level calls

query
# send a query request to server
prometheus.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 server
prometheus.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:
{"resultType"=>"matrix",
 "result"=>
  [{"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
# send a label request to server
prometheus.label('__name__')
# response from server:
["APIServiceRegistrationController_adds",
 "APIServiceRegistrationController_depth",
 ...

targets
# send a targets request to server
prometheus.targets()
# response from server:
{"activeTargets"=>
  [{"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:

rake

prometheus_api_client_ruby's People

Contributors

brian-brazil avatar d-m-u avatar glenn-m avatar prombot avatar yaacov avatar zhulik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

prometheus_api_client_ruby's Issues

Release new version

Thank you for the recent changes to revive the gem and upgrade some dependencies - edd9e93 - any timeline for releasing a new gem version?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.