prometheus-api-client 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -1
- data/lib/prometheus/api_client.rb +61 -13
- data/lib/prometheus/api_client/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ddd53e20644407d4d1a2a11b3e3116e967ac30f5
|
4
|
+
data.tar.gz: 0f659ddb1bbfb994550f353913c0dad214f70d6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fadfded50f9012c9d8e922765b078ba008c48d9ce6edf6742c4e96b1a39758b76ae1e7e3e2d0df6c7e1608ce78ed0b3d3a73266a2bc3ba39178b30c045fda9e7
|
7
|
+
data.tar.gz: d0680011ec2ca3fecda3e4daeb66fcd2db1bb92310b03c77842845fd482a7c21f6b455b77acb1e14431da10d1c8f392f022e72cc72319b5293cbfb3f2e41c3df
|
data/README.md
CHANGED
@@ -1,7 +1,16 @@
|
|
1
|
-
# Prometheus Ruby Client
|
1
|
+
# Prometheus API Ruby Client
|
2
|
+
|
3
|
+
[![Gem Version][1]](http://badge.fury.io/rb/prometheus-api-client)
|
4
|
+
[![Build Status][2]](http://travis-ci.org/yaacov/prometheus_api_client_ruby)
|
5
|
+
[![Build Status][3]](https://codeclimate.com/github/yaacov/prometheus_api_client_ruby)
|
6
|
+
[![Coverage Status][4]](https://coveralls.io/github/yaacov/prometheus_api_client_ruby?branch=master)
|
2
7
|
|
3
8
|
A Ruby library for reading Prometheus metrics API.
|
4
9
|
|
10
|
+
### Authentication proxy
|
11
|
+
|
12
|
+
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.
|
13
|
+
|
5
14
|
## Usage
|
6
15
|
|
7
16
|
### Overview
|
@@ -29,3 +38,8 @@ rspec:
|
|
29
38
|
```bash
|
30
39
|
rake
|
31
40
|
```
|
41
|
+
|
42
|
+
[1]: https://badge.fury.io/rb/prometheus-api-client.svg
|
43
|
+
[2]: https://secure.travis-ci.org/yaacov/prometheus_api_client_ruby.svg
|
44
|
+
[3]: https://codeclimate.com/github/yaacov/prometheus_api_client_ruby.svg
|
45
|
+
[4]: https://coveralls.io/repos/github/yaacov/prometheus_api_client_ruby/badge.svg
|
@@ -1,28 +1,76 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
+
require 'uri'
|
3
4
|
require 'faraday'
|
4
5
|
|
5
6
|
module Prometheus
|
6
7
|
# Client is a ruby implementation for a Prometheus compatible api_client.
|
7
8
|
module ApiClient
|
9
|
+
DEFAULT_HOST = 'localhost'.freeze
|
10
|
+
DEFAULT_SCHEME = 'http'.freeze
|
11
|
+
DEFAULT_PORT = 9090
|
12
|
+
DEFAULT_PATH = '/api/v1/'.freeze
|
13
|
+
DEFAULT_CREDENTIALS = {}.freeze
|
14
|
+
DEFAULT_OPTIONS = {}.freeze
|
15
|
+
|
8
16
|
# Returns a default client object
|
9
|
-
def self.client(
|
10
|
-
|
11
|
-
|
17
|
+
def self.client(host = DEFAULT_HOST, args = {})
|
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)
|
25
|
+
|
26
|
+
Faraday.new(
|
27
|
+
prometheus_args(host, args),
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
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
|
+
def self.prometheus_proxy(options)
|
45
|
+
options[:http_proxy_uri] if options[:http_proxy_uri]
|
46
|
+
end
|
12
47
|
|
13
|
-
|
48
|
+
def self.prometheus_verify_ssl(options)
|
49
|
+
return unless options[:verify_ssl]
|
50
|
+
|
51
|
+
{
|
52
|
+
verify: options[:verify_ssl] != OpenSSL::SSL::VERIFY_NONE,
|
53
|
+
cert_store: options[:ssl_cert_store],
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.prometheus_headers(credentials)
|
58
|
+
return unless credentials[:token]
|
59
|
+
|
60
|
+
{
|
61
|
+
Authorization: 'Bearer ' + credentials[:token].to_s,
|
62
|
+
}
|
14
63
|
end
|
15
64
|
|
16
|
-
def self.prometheus_args(
|
65
|
+
def self.prometheus_args(host, args = {})
|
17
66
|
{
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end,
|
67
|
+
url: prometheus_uri(
|
68
|
+
host, args[:scheme], args[:port], args[:path]
|
69
|
+
),
|
70
|
+
proxy: prometheus_proxy(args[:options]),
|
71
|
+
ssl: prometheus_verify_ssl(args[:options]),
|
72
|
+
headers: prometheus_headers(args[:credentials]),
|
73
|
+
request: { open_timeout: 2, timeout: 5 },
|
26
74
|
}
|
27
75
|
end
|
28
76
|
end
|