prometheus-api-client 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 905999226f7bda4a27b8a4919b4483e297c363eb
4
- data.tar.gz: d4765428ac8620f0b9629d47359bb702a25abdcd
3
+ metadata.gz: 9da5dea98ff711d07aa783e2f5b3b0b161de5b7b
4
+ data.tar.gz: b4e8224c8c64ac20f3cf198a3e220939776cc09c
5
5
  SHA512:
6
- metadata.gz: '08df780379f2a4e2d7b099931f936fc02d36351dd8452f4b5627fee2f8f68df83bfc4c474e6ea634cd6ca7b40e5c36fb3d15fb43bd744cbd04cd333e577bd0dd'
7
- data.tar.gz: 8ebe88a2fce0fe01fe4428972ea881aae45538f508fdba7caabe98b27521d42def3dc4201dcb43ea292079bfa258726a0c3b9df4f15ed557b3e95195a793010b
6
+ metadata.gz: 63bfbf3c0fd54a06618d612baedf24d53172034b5a9addc9a6564427030cd01d6dfd553f159a94938bb52b5aa2212169c6afc4e448529ca0bd3d7a63fc83675b
7
+ data.tar.gz: 04eb576c2927b15caa82fde48e3c8b094935897957927096d271c5488ea01313e4915fa500d9913d05f1647666d314324fb58a528335ef0ffa6844ae771da57d
data/README.md CHANGED
@@ -25,11 +25,11 @@ prometheus = Prometheus::ApiClient.client
25
25
 
26
26
  prometheus.get(
27
27
  "query_range",
28
- :query => "sum(container_cpu_usage_seconds_total" \
29
- "{container_name=\"prometheus-hgv4s\",job=\"kubernetes-nodes\"})",
30
- :start => "2015-07-01T20:10:30.781Z",
31
- :end => "2015-07-02T20:10:30.781Z",
32
- :step => "120s"
28
+ query: "sum(container_cpu_usage_seconds_total" \
29
+ "{container_name=\"prometheus-hgv4s\",job=\"kubernetes-nodes\"})",
30
+ start: "2015-07-01T20:10:30.781Z",
31
+ end: "2015-07-02T20:10:30.781Z",
32
+ step: "120s"
33
33
  )
34
34
  ```
35
35
 
@@ -47,7 +47,7 @@ prometheus REST server, this client can use ssl and authentication headears.
47
47
 
48
48
  ```ruby
49
49
  # return a client for host https://example.com/api/v1/ using a Bearer token "TopSecret"
50
- prometheus = Prometheus::ApiClient.client(url: 'https://example.com:443',
50
+ prometheus = Prometheus::ApiClient.client(url: 'https://example.com:443',
51
51
  credentials: {token: 'TopSecret'})
52
52
  ```
53
53
 
@@ -57,25 +57,23 @@ prometheus = Prometheus::ApiClient.client(url: 'https://example.com:443',
57
57
 
58
58
  # send a query request to server
59
59
  prometheus.query(
60
- :query => "sum(container_cpu_usage_seconds_total" \
61
- "{container_name=\"prometheus-hgv4s\",job=\"kubernetes-nodes\"})",
62
- :time => "2015-07-01T20:10:30.781Z",
60
+ query: "sum(container_cpu_usage_seconds_total" \
61
+ "{container_name=\"prometheus-hgv4s\",job=\"kubernetes-nodes\"})",
62
+ time: "2015-07-01T20:10:30.781Z",
63
63
  )
64
64
  ```
65
65
 
66
66
  ```ruby
67
67
  # send a query_range request to server
68
68
  prometheus.query_range(
69
- :query => "sum(container_cpu_usage_seconds_total" \
70
- "{container_name=\"prometheus-hgv4s\",job=\"kubernetes-nodes\"})",
71
- :start => "2015-07-01T20:10:30.781Z",
72
- :end => "2015-07-02T20:10:30.781Z",
73
- :step => "120s"
69
+ query: "sum(container_cpu_usage_seconds_total" \
70
+ "{container_name=\"prometheus-hgv4s\",job=\"kubernetes-nodes\"})",
71
+ start: "2015-07-01T20:10:30.781Z",
72
+ end: "2015-07-02T20:10:30.781Z",
73
+ step: "120s"
74
74
  )
75
- ```
76
75
 
77
- Example of response to metrics request:
78
- ```
76
+ # response from server:
79
77
  {"resultType"=>"matrix",
80
78
  "result"=>
81
79
  [{"metric"=>
@@ -109,10 +107,8 @@ Example of response to metrics request:
109
107
  ```ruby
110
108
  # send a label request to server
111
109
  prometheus.label('__name__')
112
- ```
113
110
 
114
- Example of response to a label request:
115
- ```
111
+ # response from server:
116
112
  ["kubernetes-apiservers", "kubernetes-cadvisor", "kubernetes-nodes",
117
113
  "kubernetes-service-endpoints"]
118
114
  ```
@@ -135,8 +131,8 @@ prometheus = Prometheus::ApiClient::Cadvisor::Node.new(
135
131
 
136
132
  # send a query request to server
137
133
  prometheus.query(
138
- :query => "sum(container_cpu_usage_seconds_total)",
139
- :time => "2015-07-01T20:10:30.781Z",
134
+ query: "sum(container_cpu_usage_seconds_total)",
135
+ time: "2015-07-01T20:10:30.781Z",
140
136
  )
141
137
  ```
142
138
 
@@ -8,39 +8,42 @@ module Prometheus
8
8
  # Client contains the implementation for a Prometheus compatible api_client,
9
9
  # With special labels for the cadvisor job.
10
10
  module Cadvisor
11
- # Create a Prometheus API client:
12
- #
13
- # @param [Hash] options
14
- # @option options [String] :url Server base URL.
15
- # @option options [Hash] :params URI query unencoded key/value pairs.
16
- # @option options [Hash] :headers Unencoded HTTP header key/value pairs.
17
- # @option options [Hash] :request Request options.
18
- # @option options [Hash] :ssl SSL options.
19
- # @option options [Hash] :proxy Proxy options.
20
- #
21
- # A default client is created if options is omitted.
22
- class Node < Client
23
- def initialize(options = {})
24
- instance = options[:instance]
25
-
26
- @labels = "job=\"kubernetes-cadvisor\",instance=\"#{instance}\"," \
27
- 'id="/"'
28
- super(options)
11
+ # A client with special labels for cadvisor metrics
12
+ class CadvisorClient < Client
13
+ # Add labels to simple query variables.
14
+ #
15
+ # Example:
16
+ # "cpu_usage" => "cpu_usage{labels...}"
17
+ # "sum(cpu_usage)" => "sum(cpu_usage{labels...})"
18
+ # "rate(cpu_usage[5m])" => "rate(cpu_usage{labels...}[5m])"
19
+ #
20
+ # Note:
21
+ # Not supporting more complex queries.
22
+ def update_query(query, labels)
23
+ query.sub(/(?<r>\[.+\])?(?<f>[)])?$/, "{#{labels}}\\k<r>\\k<f>")
29
24
  end
30
25
 
31
- def query(options)
26
+ # Issues a get request to the low level client.
27
+ # Update the query options to use specific labels
28
+ def get(command, options)
32
29
  options[:query] = update_query(options[:query], @labels)
33
- super(options)
30
+ @client.get(command, options)
34
31
  end
32
+ end
35
33
 
36
- def query_range(options)
37
- options[:query] = update_query(options[:query], @labels)
34
+ # A client with special labels for node cadvisor metrics
35
+ class Node < CadvisorClient
36
+ def initialize(options = {})
37
+ instance = options[:instance]
38
+
39
+ @labels = "job=\"kubernetes-cadvisor\",instance=\"#{instance}\"," \
40
+ 'id="/"'
38
41
  super(options)
39
42
  end
40
43
  end
41
44
 
42
45
  # A client with special labels for pod cadvisor metrics
43
- class Pod < Client
46
+ class Pod < CadvisorClient
44
47
  def initialize(options = {})
45
48
  pod_name = options[:pod_name]
46
49
  namespace = options[:namespace] || 'default'
@@ -49,20 +52,10 @@ module Prometheus
49
52
  "pod_name=\"#{pod_name}\",container_name=\"POD\""
50
53
  super(options)
51
54
  end
52
-
53
- def query(options)
54
- options[:query] = update_query(options[:query], @labels)
55
- super(options)
56
- end
57
-
58
- def query_range(options)
59
- options[:query] = update_query(options[:query], @labels)
60
- super(options)
61
- end
62
55
  end
63
56
 
64
57
  # A client with special labels for container cadvisor metrics
65
- class Container < Client
58
+ class Container < CadvisorClient
66
59
  def initialize(options = {})
67
60
  container_name = args[:container_name]
68
61
  pod_name = args[:pod_name]
@@ -72,16 +65,6 @@ module Prometheus
72
65
  "pod_name=\"#{pod_name}\",container_name=\"#{container_name}\""
73
66
  super(options)
74
67
  end
75
-
76
- def query(options)
77
- options[:query] = update_query(options[:query], @labels)
78
- super(options)
79
- end
80
-
81
- def query_range(options)
82
- options[:query] = update_query(options[:query], @labels)
83
- super(options)
84
- end
85
68
  end
86
69
  end
87
70
  end
@@ -105,19 +105,6 @@ module Prometheus
105
105
  raise RequestError, 'Bad response from server'
106
106
  end
107
107
 
108
- # Add labels to simple query variables.
109
- #
110
- # Example:
111
- # "cpu_usage" => "cpu_usage{labels...}"
112
- # "sum(cpu_usage)" => "sum(cpu_usage{labels...})"
113
- # "rate(cpu_usage[5m])" => "rate(cpu_usage{labels...}[5m])"
114
- #
115
- # Note:
116
- # Not supporting more complex queries.
117
- def update_query(query, labels)
118
- query.sub(/(?<r>\[.+\])?(?<f>[)])?$/, "{#{labels}}\\k<r>\\k<f>")
119
- end
120
-
121
108
  # Helper function to evalueate the low level proxy option
122
109
  def faraday_proxy(options)
123
110
  options[:http_proxy_uri] if options[:http_proxy_uri]
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Prometheus
4
4
  module ApiClient
5
- VERSION = '0.3.2'
5
+ VERSION = '0.3.3'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prometheus-api-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yaacov Zamir
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-07 00:00:00.000000000 Z
11
+ date: 2017-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: quantile