Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A Ruby library for reading metrics stored on a Prometheus server

License

NotificationsYou must be signed in to change notification settings

prometheus/prometheus_api_client_ruby

Gem VersionBuild StatusCoverage 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 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',)
# 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 serverprometheus.label('__name__')
# response from server:["APIServiceRegistrationController_adds", "APIServiceRegistrationController_depth", ...
targets
# send a targets request to serverprometheus.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 withbundle install and run tests withrspec:

rake

About

A Ruby library for reading metrics stored on a Prometheus server

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp