prometheus-api-client 0.0.2 → 0.1.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 +21 -3
- data/lib/prometheus/api_client.rb +21 -35
- data/lib/prometheus/api_client/client.rb +42 -0
- data/lib/prometheus/api_client/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6fa60b4ccdbfed4c2141142a9588169498b2b403
|
4
|
+
data.tar.gz: 9033f3fc05d7beffcb794ddf427fb12b458ce187
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4bc1d913b47c48321189a7cd8d1d085f9f156d000735665a85aac89f1a26b1acb7b8638fad267bb40a9b671258f34b0f5fc32f1ccf1d72b85b8b94268e264ffb
|
7
|
+
data.tar.gz: 951b1b31db41c3152704eef094545578f0cb714067f4bfcdd8666d1998a5d742600b428e41b6ccc329754b2f3cdc1f46f971679ade1ad994855afae8836ef31f
|
data/README.md
CHANGED
@@ -7,9 +7,11 @@
|
|
7
7
|
|
8
8
|
A Ruby library for reading Prometheus metrics API.
|
9
9
|
|
10
|
-
|
10
|
+
## Install
|
11
11
|
|
12
|
-
|
12
|
+
```
|
13
|
+
gem install prometheus-api-client
|
14
|
+
```
|
13
15
|
|
14
16
|
## Usage
|
15
17
|
|
@@ -18,7 +20,7 @@ If an authentication proxy ( e.g. oauth2 ) is used in a layer above the promethe
|
|
18
20
|
```ruby
|
19
21
|
require 'prometheus/api_client'
|
20
22
|
|
21
|
-
#
|
23
|
+
# return a client for host http://localhost:9090/api/v1/
|
22
24
|
prometheus = Prometheus::ApiClient.client
|
23
25
|
|
24
26
|
prometheus.get(
|
@@ -30,6 +32,22 @@ prometheus.get(
|
|
30
32
|
)
|
31
33
|
```
|
32
34
|
|
35
|
+
#### Changing server hostname
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
# return a client for host http://example.com:9090/api/v1/
|
39
|
+
prometheus = Prometheus::ApiClient.client('example.com')
|
40
|
+
```
|
41
|
+
|
42
|
+
#### Authentication proxy
|
43
|
+
|
44
|
+
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.
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
# return a client for host https://example.com/api/v1/
|
48
|
+
prometheus = Prometheus::ApiClient.client('example.com', scheme: 'https', port: 443)
|
49
|
+
```
|
50
|
+
|
33
51
|
## Tests
|
34
52
|
|
35
53
|
Install necessary development gems with `bundle install` and run tests with
|
@@ -1,46 +1,31 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
3
|
require 'uri'
|
4
|
-
require '
|
4
|
+
require 'openssl'
|
5
|
+
require 'prometheus/api_client/client'
|
5
6
|
|
6
7
|
module Prometheus
|
7
8
|
# Client is a ruby implementation for a Prometheus compatible api_client.
|
8
9
|
module ApiClient
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
DEFAULT_ENTRYPOINT = 'http://localhost:9090'.freeze
|
11
|
+
DEFAULT_ARGS = {
|
12
|
+
path: '/api/v1/',
|
13
|
+
credentials: {},
|
14
|
+
options: {
|
15
|
+
open_timeout: 2,
|
16
|
+
timeout: 5,
|
17
|
+
},
|
18
|
+
}.freeze
|
15
19
|
|
16
20
|
# Returns a default client object
|
17
|
-
def self.client(
|
18
|
-
args =
|
19
|
-
scheme: DEFAULT_SCHEME,
|
20
|
-
port: DEFAULT_PORT,
|
21
|
-
path: DEFAULT_PATH,
|
22
|
-
credentials: DEFAULT_CREDENTIALS,
|
23
|
-
options: DEFAULT_OPTIONS,
|
24
|
-
}.merge(args)
|
21
|
+
def self.client(entrypoint = DEFAULT_ENTRYPOINT, args = {})
|
22
|
+
args = DEFAULT_ARGS.merge(args)
|
25
23
|
|
26
|
-
|
27
|
-
prometheus_args(
|
24
|
+
Client.new(
|
25
|
+
prometheus_args(entrypoint, args),
|
28
26
|
)
|
29
27
|
end
|
30
28
|
|
31
|
-
def self.prometheus_uri(host, scheme, port, path)
|
32
|
-
builder = {
|
33
|
-
http: URI::HTTP,
|
34
|
-
https: URI::HTTPS,
|
35
|
-
}[scheme.to_sym]
|
36
|
-
|
37
|
-
builder.build(
|
38
|
-
host: host,
|
39
|
-
port: port,
|
40
|
-
path: path,
|
41
|
-
).to_s
|
42
|
-
end
|
43
|
-
|
44
29
|
def self.prometheus_proxy(options)
|
45
30
|
options[:http_proxy_uri] if options[:http_proxy_uri]
|
46
31
|
end
|
@@ -62,15 +47,16 @@ module Prometheus
|
|
62
47
|
}
|
63
48
|
end
|
64
49
|
|
65
|
-
def self.prometheus_args(
|
50
|
+
def self.prometheus_args(entrypoint, args = {})
|
66
51
|
{
|
67
|
-
url:
|
68
|
-
host, args[:scheme], args[:port], args[:path]
|
69
|
-
),
|
52
|
+
url: entrypoint + args[:path],
|
70
53
|
proxy: prometheus_proxy(args[:options]),
|
71
54
|
ssl: prometheus_verify_ssl(args[:options]),
|
72
55
|
headers: prometheus_headers(args[:credentials]),
|
73
|
-
request: {
|
56
|
+
request: {
|
57
|
+
open_timeout: args[:options][:open_timeout],
|
58
|
+
timeout: args[:options][:timeout],
|
59
|
+
},
|
74
60
|
}
|
75
61
|
end
|
76
62
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'faraday'
|
5
|
+
|
6
|
+
module Prometheus
|
7
|
+
# Client is a ruby implementation for a Prometheus compatible api_client.
|
8
|
+
module ApiClient
|
9
|
+
# Client contains the implementation for a Prometheus compatible api_client.
|
10
|
+
class Client
|
11
|
+
class RequestError < StandardError; end
|
12
|
+
|
13
|
+
def initialize(args)
|
14
|
+
@client = Faraday.new(args)
|
15
|
+
end
|
16
|
+
|
17
|
+
def query(options)
|
18
|
+
run_command('query', options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def query_range(options)
|
22
|
+
run_command('query_range', options)
|
23
|
+
end
|
24
|
+
|
25
|
+
def label(tag, options)
|
26
|
+
run_command("label/#{tag}/values", options)
|
27
|
+
end
|
28
|
+
|
29
|
+
def get(command, options)
|
30
|
+
@client.get(command, options)
|
31
|
+
end
|
32
|
+
|
33
|
+
def run_command(command, options)
|
34
|
+
response = get(command, options)
|
35
|
+
|
36
|
+
JSON.parse(response.body)['data']
|
37
|
+
rescue
|
38
|
+
raise RequestError, 'Bad response from server'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
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.0
|
4
|
+
version: 0.1.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-08-
|
11
|
+
date: 2017-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: quantile
|
@@ -48,6 +48,7 @@ files:
|
|
48
48
|
- README.md
|
49
49
|
- lib/prometheus.rb
|
50
50
|
- lib/prometheus/api_client.rb
|
51
|
+
- lib/prometheus/api_client/client.rb
|
51
52
|
- lib/prometheus/api_client/version.rb
|
52
53
|
homepage: https://github.com/yaacov/prometheus_api_client_ruby
|
53
54
|
licenses:
|
@@ -72,5 +73,5 @@ rubyforge_project:
|
|
72
73
|
rubygems_version: 2.6.11
|
73
74
|
signing_key:
|
74
75
|
specification_version: 4
|
75
|
-
summary: A suite of reading metric
|
76
|
+
summary: A suite of reading metric values that are exposed through an API interface.
|
76
77
|
test_files: []
|