-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathget_metrics.rb
42 lines (39 loc) · 1.32 KB
/
get_metrics.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require 'prometheus/api_client'
# returns a client
prometheus = Prometheus::ApiClient.client(url: 'http://example.com:8080')
prometheus.query_range(
query: 'container_cpu_usage_seconds_total{id="/"}',
start: '2017-08-07T06:10:30.781Z',
end: '2017-08-07T06:14:30.781Z',
step: '120s',
)
# will result in a hash containing the results data struct:
#
# {"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"]]}]}