prometheus-api-client 0.5.2 → 0.6.0
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 +4 -4
- data/README.md +0 -36
- data/lib/prometheus/api_client.rb +0 -1
- data/lib/prometheus/api_client/version.rb +1 -1
- metadata +2 -3
- data/lib/prometheus/api_client/cadvisor.rb +0 -90
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9d556204a2bc7ffb30d4a1342ed4db68f0ca91c
|
4
|
+
data.tar.gz: 9bd9dcae811c232acd507cc2865e3d005d4d7417
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 554eece785a3c352385705ebefe7a4b0c83702d482beed3908b1e97f7b588948f71a2e35fcf5c81913c0e1bc1d22b915dc429cd8c200efcd76aea607d7f29d58
|
7
|
+
data.tar.gz: 529325a6d350c546274187cca962de4e84f8acf991c4b1f9fcc2ce26695c2550f4d5b2f6a6d516cb8b352593af8eec2ade867bc08766b38ebce01893340c29b2
|
data/README.md
CHANGED
@@ -173,42 +173,6 @@ prometheus.targets()
|
|
173
173
|
|
174
174
|
```
|
175
175
|
|
176
|
-
#### cAdvisor specialize client
|
177
|
-
|
178
|
-
A cAdvisor client is a client that add object specific labels to each REST call,
|
179
|
-
objects available are Node, Pod and Container.
|
180
|
-
|
181
|
-
###### Node
|
182
|
-
|
183
|
-
Add the instance label, user must declare the instance on client creation.
|
184
|
-
|
185
|
-
###### Pod
|
186
|
-
|
187
|
-
Add the pod_name label, user must declare the pod_name on client creation.
|
188
|
-
|
189
|
-
###### Container
|
190
|
-
|
191
|
-
Add the container_name and pod_name labels, user must declare container_name and pod_name on client creation.
|
192
|
-
|
193
|
-
###### Example
|
194
|
-
|
195
|
-
```ruby
|
196
|
-
|
197
|
-
# create a client for cAdvisor metrics of a Node instance 'example.com'
|
198
|
-
# connected to a Prometheus server listening on http://example.com:8080
|
199
|
-
prometheus = Prometheus::ApiClient::Cadvisor::Node.new(
|
200
|
-
instance: 'example.com',
|
201
|
-
url: 'http://example.com:8080',
|
202
|
-
)
|
203
|
-
|
204
|
-
# send a query request to server
|
205
|
-
prometheus.query(query: 'sum(container_cpu_usage_seconds_total)')
|
206
|
-
```
|
207
|
-
```
|
208
|
-
# response from server:
|
209
|
-
{"resultType"=>"vector", "result"=>[{"metric"=>{}, "value"=>[1502350741.161, "6606.310387038"]}]}
|
210
|
-
```
|
211
|
-
|
212
176
|
## Tests
|
213
177
|
|
214
178
|
Install necessary development gems with `bundle install` and run tests with
|
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.
|
4
|
+
version: 0.6.0
|
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-
|
11
|
+
date: 2017-09-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -34,7 +34,6 @@ files:
|
|
34
34
|
- README.md
|
35
35
|
- lib/prometheus.rb
|
36
36
|
- lib/prometheus/api_client.rb
|
37
|
-
- lib/prometheus/api_client/cadvisor.rb
|
38
37
|
- lib/prometheus/api_client/client.rb
|
39
38
|
- lib/prometheus/api_client/version.rb
|
40
39
|
homepage: https://github.com/yaacov/prometheus_api_client_ruby
|
@@ -1,90 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'prometheus/api_client/client'
|
4
|
-
|
5
|
-
module Prometheus
|
6
|
-
# Client is a ruby implementation for a Prometheus compatible api_client.
|
7
|
-
module ApiClient
|
8
|
-
# Client contains the implementation for a Prometheus compatible api_client,
|
9
|
-
# With special labels for the cadvisor job.
|
10
|
-
module Cadvisor
|
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>")
|
24
|
-
end
|
25
|
-
|
26
|
-
# Issues a get request to the low level client.
|
27
|
-
# Update the query options to use specific labels
|
28
|
-
def get(command, options)
|
29
|
-
options[:query] = update_query(options[:query], @labels)
|
30
|
-
@client.get(command, options)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
# A client with special labels for node cadvisor metrics
|
35
|
-
class Node < CadvisorClient
|
36
|
-
def initialize(options = {})
|
37
|
-
instance = options[:instance]
|
38
|
-
|
39
|
-
# if no instance is given, assume we want data on all nodes
|
40
|
-
@labels = if instance
|
41
|
-
'job="kubernetes-cadvisor",id="/",' \
|
42
|
-
"instance=\"#{instance}\""
|
43
|
-
else
|
44
|
-
'job="kubernetes-cadvisor",id="/"'
|
45
|
-
end
|
46
|
-
|
47
|
-
super(options)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
# A client with special labels for pod cadvisor metrics
|
52
|
-
class Pod < CadvisorClient
|
53
|
-
def initialize(options = {})
|
54
|
-
pod_name = options[:pod_name]
|
55
|
-
namespace = options[:namespace] || 'default'
|
56
|
-
|
57
|
-
# if no pod_name is given, assume we want data on all pods
|
58
|
-
@labels = if pod_name
|
59
|
-
'job="kubernetes-cadvisor",container_name="POD",' \
|
60
|
-
"pod_name=\"#{pod_name}\",namespace=\"#{namespace}\""
|
61
|
-
else
|
62
|
-
'job="kubernetes-cadvisor",container_name="POD"'
|
63
|
-
end
|
64
|
-
|
65
|
-
super(options)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
# A client with special labels for container cadvisor metrics
|
70
|
-
class Container < CadvisorClient
|
71
|
-
def initialize(options = {})
|
72
|
-
container_name = options[:container_name]
|
73
|
-
pod_name = options[:pod_name]
|
74
|
-
namespace = options[:namespace] || 'default'
|
75
|
-
|
76
|
-
# if no container_name is given, assume we want data on all containers
|
77
|
-
@labels = if container_name
|
78
|
-
'job="kubernetes-cadvisor",' \
|
79
|
-
"namespace=\"#{namespace}\",pod_name=\"#{pod_name}\"," \
|
80
|
-
"container_name=\"#{container_name}\""
|
81
|
-
else
|
82
|
-
'job="kubernetes-cadvisor",container_name!="POD"'
|
83
|
-
end
|
84
|
-
|
85
|
-
super(options)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|