fluent-plugin-prometheus 1.7.0 → 2.0.2
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/.github/workflows/linux.yml +32 -0
- data/ChangeLog +39 -0
- data/README.md +28 -4
- data/fluent-plugin-prometheus.gemspec +3 -3
- data/lib/fluent/plugin/in_prometheus.rb +147 -81
- data/lib/fluent/plugin/in_prometheus/async_wrapper.rb +47 -0
- data/lib/fluent/plugin/in_prometheus_monitor.rb +19 -11
- data/lib/fluent/plugin/in_prometheus_output_monitor.rb +62 -31
- data/lib/fluent/plugin/in_prometheus_tail_monitor.rb +16 -13
- data/lib/fluent/plugin/prometheus.rb +36 -23
- data/lib/fluent/plugin/prometheus/placeholder_expander.rb +132 -0
- data/spec/fluent/plugin/filter_prometheus_spec.rb +20 -10
- data/spec/fluent/plugin/in_prometheus_monitor_spec.rb +0 -1
- data/spec/fluent/plugin/in_prometheus_spec.rb +225 -0
- data/spec/fluent/plugin/in_prometheus_tail_monitor_spec.rb +42 -0
- data/spec/fluent/plugin/out_prometheus_spec.rb +43 -9
- data/spec/fluent/plugin/prometheus/placeholder_expander_spec.rb +110 -0
- data/spec/fluent/plugin/shared.rb +58 -110
- metadata +19 -11
- data/spec/fluent/plugin/prometheus_spec.rb +0 -101
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 949d2ec196fae78bdfcbbfeae20d718e7a3a34a6ceba9ba665d1a7d40326d529
|
4
|
+
data.tar.gz: c1adf9a63565a38141247034157f84aadb85336e5add24ca6d99c126cd8e01d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7199fc669d4c389fa5638615d16a4fdb29a27cc959b60c3ec6e3031328a9cb052bb6169733c73e66f659ec929aa3faffd8869187dc70f6eff361263b3304ecb0
|
7
|
+
data.tar.gz: acfbe23681c5bf801ae10c41a265dfb358b05516b79d0e2944317469b0b4be8aad5b1fbda246d9e4caa0e75f473428046015232c0900689ccb629a3b7c5b72a8
|
@@ -0,0 +1,32 @@
|
|
1
|
+
name: linux
|
2
|
+
on:
|
3
|
+
- push
|
4
|
+
- pull_request
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
runs-on: ${{ matrix.os }}
|
8
|
+
continue-on-error: ${{ matrix.experimental }}
|
9
|
+
strategy:
|
10
|
+
fail-fast: false
|
11
|
+
matrix:
|
12
|
+
ruby: [ '2.5', '2.6', '2.7', '3.0' ]
|
13
|
+
os:
|
14
|
+
- ubuntu-latest
|
15
|
+
experimental: [false]
|
16
|
+
include:
|
17
|
+
- ruby: head
|
18
|
+
os: ubuntu-latest
|
19
|
+
experimental: true
|
20
|
+
name: Ruby ${{ matrix.ruby }} unit testing on ${{ matrix.os }}
|
21
|
+
steps:
|
22
|
+
- uses: actions/checkout@v2
|
23
|
+
- uses: ruby/setup-ruby@v1
|
24
|
+
with:
|
25
|
+
ruby-version: ${{ matrix.ruby }}
|
26
|
+
- name: unit testing
|
27
|
+
env:
|
28
|
+
CI: true
|
29
|
+
run: |
|
30
|
+
gem install bundler rake
|
31
|
+
bundle install --jobs 4 --retry 3
|
32
|
+
bundle exec rake spec
|
data/ChangeLog
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
Release 2.0.2 - 2021/08/02
|
2
|
+
|
3
|
+
* in_prometheus_output_monitor: Follow Fluentd's core metrics mechanism
|
4
|
+
|
5
|
+
Release 2.0.1 - 2021/04/08
|
6
|
+
|
7
|
+
* out_prometheus: Allow for lookup by symbol as well as string
|
8
|
+
|
9
|
+
Release 2.0.0 - 2021/02/18
|
10
|
+
|
11
|
+
* Update prometheus-client dependency to 2.1.0 or later
|
12
|
+
|
13
|
+
Release 1.8.5 - 2020/11/24
|
14
|
+
|
15
|
+
* in_prometheus_monitor: Support USR2 reload
|
16
|
+
|
17
|
+
Release 1.8.4 - 2020/09/24
|
18
|
+
|
19
|
+
* in_prometheus_output_monitor: Add gauge_all parameter
|
20
|
+
|
21
|
+
Release 1.8.3 - 2020/08/24
|
22
|
+
|
23
|
+
* Fix resourcr leak in async-http based server
|
24
|
+
|
25
|
+
Release 1.8.2 - 2020/07/17
|
26
|
+
|
27
|
+
* in_prometheus_output_monitor/in_prometheus_tail_monitor: Support USR2 reload
|
28
|
+
|
29
|
+
Release 1.8.1 - 2020/07/06
|
30
|
+
|
31
|
+
* Fix aggregate bug with async-http
|
32
|
+
|
33
|
+
Release 1.8.0 - 2020/04/17
|
34
|
+
|
35
|
+
* Use http_server helper
|
36
|
+
* Require fluentd v1.9.1 or later
|
37
|
+
|
38
|
+
|
39
|
+
For older releases, see commits on github repository.
|
data/README.md
CHANGED
@@ -8,9 +8,13 @@ A fluent plugin that instruments metrics from records and exposes them via web i
|
|
8
8
|
|
9
9
|
| fluent-plugin-prometheus | fluentd | ruby |
|
10
10
|
|--------------------------|------------|--------|
|
11
|
-
| 1.x.y | >=
|
11
|
+
| 1.x.y | >= v1.9.1 | >= 2.4 |
|
12
|
+
| 1.[0-7].y | >= v0.14.8 | >= 2.1 |
|
12
13
|
| 0.x.y | >= v0.12.0 | >= 1.9 |
|
13
14
|
|
15
|
+
Since v1.8.0, fluent-plugin-prometheus uses [http_server helper](https://docs.fluentd.org/plugin-helper-overview/api-plugin-helper-http_server) to launch HTTP server.
|
16
|
+
If you want to handle lots of connections, install `async-http` gem.
|
17
|
+
|
14
18
|
## Installation
|
15
19
|
|
16
20
|
Add this line to your application's Gemfile:
|
@@ -63,6 +67,19 @@ More configuration parameters:
|
|
63
67
|
When using multiple workers, each worker binds to port + `fluent_worker_id`.
|
64
68
|
To scrape metrics from all workers at once, you can access http://localhost:24231/aggregated_metrics.
|
65
69
|
|
70
|
+
#### TLS setting
|
71
|
+
|
72
|
+
Use `<trasnport tls>`. See [transport config article](https://docs.fluentd.org/configuration/transport-section) for more details.
|
73
|
+
|
74
|
+
```
|
75
|
+
<source>
|
76
|
+
@type prometheus
|
77
|
+
<transport tls>
|
78
|
+
# TLS parameters...
|
79
|
+
</transport
|
80
|
+
</source>
|
81
|
+
```
|
82
|
+
|
66
83
|
### prometheus_monitor input plugin
|
67
84
|
|
68
85
|
This plugin collects internal metrics in Fluentd. The metrics are similar to/part of [monitor_agent](https://docs.fluentd.org/input/monitor_agent).
|
@@ -71,7 +88,7 @@ This plugin collects internal metrics in Fluentd. The metrics are similar to/par
|
|
71
88
|
#### Exposed metrics
|
72
89
|
|
73
90
|
- `fluentd_status_buffer_queue_length`
|
74
|
-
- `
|
91
|
+
- `fluentd_status_buffer_total_bytes`
|
75
92
|
- `fluentd_status_retry_count`
|
76
93
|
- `fluentd_status_buffer_newest_timekey` from fluentd v1.4.2
|
77
94
|
- `fluentd_status_buffer_oldest_timekey` from fluentd v1.4.2
|
@@ -107,7 +124,7 @@ Metrics for output
|
|
107
124
|
- `fluentd_output_status_emit_records`
|
108
125
|
- `fluentd_output_status_write_count`
|
109
126
|
- `fluentd_output_status_rollback_count`
|
110
|
-
- `fluentd_output_status_flush_time_count` from fluentd v1.6.0
|
127
|
+
- `fluentd_output_status_flush_time_count` in milliseconds from fluentd v1.6.0
|
111
128
|
- `fluentd_output_status_slow_flush_count` from fluentd v1.6.0
|
112
129
|
|
113
130
|
Metrics for buffer
|
@@ -135,6 +152,7 @@ More configuration parameters:
|
|
135
152
|
|
136
153
|
- `<labels>`: additional labels for this metric (optional). See [Labels](#labels)
|
137
154
|
- `interval`: interval to update monitor_agent information in seconds (default: 5)
|
155
|
+
- `gauge_all`: Specify metric type. If `true`, use `gauge` type. If `false`, use `counter` type. Since v2, this parameter will be removed and use `counter` type.
|
138
156
|
|
139
157
|
### prometheus_tail_monitor input plugin
|
140
158
|
|
@@ -369,7 +387,13 @@ Reserved placeholders are:
|
|
369
387
|
- `${worker_id}`: fluent worker id
|
370
388
|
- `${tag}`: tag name
|
371
389
|
- only available in Prometheus output/filter plugin
|
372
|
-
|
390
|
+
- `${tag_parts[N]}` refers to the Nth part of the tag.
|
391
|
+
- only available in Prometheus output/filter plugin
|
392
|
+
- `${tag_prefix[N]}` refers to the [0..N] part of the tag.
|
393
|
+
- only available in Prometheus output/filter plugin
|
394
|
+
- `${tag_suffix[N]}` refers to the [`tagsize`-1-N..] part of the tag.
|
395
|
+
- where `tagsize` is the size of tag which is splitted with `.` (when tag is `1.2.3`, then `tagsize` is 3)
|
396
|
+
- only available in Prometheus output/filter plugin
|
373
397
|
|
374
398
|
### top-level labels and labels inside metric
|
375
399
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "fluent-plugin-prometheus"
|
3
|
-
spec.version = "
|
3
|
+
spec.version = "2.0.2"
|
4
4
|
spec.authors = ["Masahiro Sano"]
|
5
5
|
spec.email = ["sabottenda@gmail.com"]
|
6
6
|
spec.summary = %q{A fluent plugin that collects metrics and exposes for Prometheus.}
|
@@ -13,8 +13,8 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
14
14
|
spec.require_paths = ["lib"]
|
15
15
|
|
16
|
-
spec.add_dependency "fluentd", ">=
|
17
|
-
spec.add_dependency "prometheus-client", "
|
16
|
+
spec.add_dependency "fluentd", ">= 1.9.1", "< 2"
|
17
|
+
spec.add_dependency "prometheus-client", ">= 2.1.0"
|
18
18
|
spec.add_development_dependency "bundler"
|
19
19
|
spec.add_development_dependency "rake"
|
20
20
|
spec.add_development_dependency "rspec"
|
@@ -2,13 +2,13 @@ require 'fluent/plugin/input'
|
|
2
2
|
require 'fluent/plugin/prometheus'
|
3
3
|
require 'fluent/plugin/prometheus_metrics'
|
4
4
|
require 'net/http'
|
5
|
-
require '
|
5
|
+
require 'openssl'
|
6
6
|
|
7
7
|
module Fluent::Plugin
|
8
8
|
class PrometheusInput < Fluent::Plugin::Input
|
9
9
|
Fluent::Plugin.register_input('prometheus', self)
|
10
10
|
|
11
|
-
helpers :thread
|
11
|
+
helpers :thread, :http_server
|
12
12
|
|
13
13
|
config_param :bind, :string, default: '0.0.0.0'
|
14
14
|
config_param :port, :integer, default: 24231
|
@@ -17,30 +17,25 @@ module Fluent::Plugin
|
|
17
17
|
|
18
18
|
desc 'Enable ssl configuration for the server'
|
19
19
|
config_section :ssl, required: false, multi: false do
|
20
|
-
config_param :enable, :bool, default: false
|
20
|
+
config_param :enable, :bool, default: false, deprecated: 'Use <transport tls> section'
|
21
21
|
|
22
22
|
desc 'Path to the ssl certificate in PEM format. Read from file and added to conf as "SSLCertificate"'
|
23
|
-
config_param :certificate_path, :string, default: nil
|
23
|
+
config_param :certificate_path, :string, default: nil, deprecated: 'Use cert_path in <transport tls> section'
|
24
24
|
|
25
25
|
desc 'Path to the ssl private key in PEM format. Read from file and added to conf as "SSLPrivateKey"'
|
26
|
-
config_param :private_key_path, :string, default: nil
|
26
|
+
config_param :private_key_path, :string, default: nil, deprecated: 'Use private_key_path in <transport tls> section'
|
27
27
|
|
28
28
|
desc 'Path to CA in PEM format. Read from file and added to conf as "SSLCACertificateFile"'
|
29
|
-
config_param :ca_path, :string, default: nil
|
29
|
+
config_param :ca_path, :string, default: nil, deprecated: 'Use ca_path in <transport tls> section'
|
30
30
|
|
31
31
|
desc 'Additional ssl conf for the server. Ref: https://github.com/ruby/webrick/blob/master/lib/webrick/ssl.rb'
|
32
|
-
config_param :extra_conf, :hash, default:
|
32
|
+
config_param :extra_conf, :hash, default: nil, symbolize_keys: true, deprecated: 'See http helper config'
|
33
33
|
end
|
34
34
|
|
35
|
-
attr_reader :registry
|
36
|
-
|
37
|
-
attr_reader :num_workers
|
38
|
-
attr_reader :base_port
|
39
|
-
attr_reader :metrics_path
|
40
|
-
|
41
35
|
def initialize
|
42
36
|
super
|
43
37
|
@registry = ::Prometheus::Client.registry
|
38
|
+
@secure = nil
|
44
39
|
end
|
45
40
|
|
46
41
|
def configure(conf)
|
@@ -55,6 +50,7 @@ module Fluent::Plugin
|
|
55
50
|
nil
|
56
51
|
end
|
57
52
|
@num_workers = sysconf && sysconf.workers ? sysconf.workers : 1
|
53
|
+
@secure = @transport_config.protocol == :tls || (@ssl && @ssl['enable'])
|
58
54
|
|
59
55
|
@base_port = @port
|
60
56
|
@port += fluentd_worker_id
|
@@ -66,7 +62,71 @@ module Fluent::Plugin
|
|
66
62
|
|
67
63
|
def start
|
68
64
|
super
|
69
|
-
|
65
|
+
|
66
|
+
scheme = @secure ? 'https' : 'http'
|
67
|
+
log.debug "listening prometheus http server on #{scheme}:://#{@bind}:#{@port}/#{@metrics_path} for worker#{fluentd_worker_id}"
|
68
|
+
|
69
|
+
proto = @secure ? :tls : :tcp
|
70
|
+
|
71
|
+
if @ssl && @ssl['enable'] && @ssl['extra_conf']
|
72
|
+
start_webrick
|
73
|
+
return
|
74
|
+
end
|
75
|
+
|
76
|
+
begin
|
77
|
+
require 'async'
|
78
|
+
require 'fluent/plugin/in_prometheus/async_wrapper'
|
79
|
+
extend AsyncWrapper
|
80
|
+
rescue LoadError => _
|
81
|
+
# ignore
|
82
|
+
end
|
83
|
+
|
84
|
+
tls_opt = if @ssl && @ssl['enable']
|
85
|
+
ssl_config = {}
|
86
|
+
|
87
|
+
if (@ssl['certificate_path'] && @ssl['private_key_path'].nil?) || (@ssl['certificate_path'].nil? && @ssl['private_key_path'])
|
88
|
+
raise Fluent::ConfigError.new('both certificate_path and private_key_path must be defined')
|
89
|
+
end
|
90
|
+
|
91
|
+
if @ssl['certificate_path']
|
92
|
+
ssl_config['cert_path'] = @ssl['certificate_path']
|
93
|
+
end
|
94
|
+
|
95
|
+
if @ssl['private_key_path']
|
96
|
+
ssl_config['private_key_path'] = @ssl['private_key_path']
|
97
|
+
end
|
98
|
+
|
99
|
+
if @ssl['ca_path']
|
100
|
+
ssl_config['ca_path'] = @ssl['ca_path']
|
101
|
+
# Only ca_path is insecure in fluentd
|
102
|
+
# https://github.com/fluent/fluentd/blob/2236ad45197ba336fd9faf56f442252c8b226f25/lib/fluent/plugin_helper/cert_option.rb#L68
|
103
|
+
ssl_config['insecure'] = true
|
104
|
+
end
|
105
|
+
|
106
|
+
ssl_config
|
107
|
+
end
|
108
|
+
|
109
|
+
http_server_create_http_server(:in_prometheus_server, addr: @bind, port: @port, logger: log, proto: proto, tls_opts: tls_opt) do |server|
|
110
|
+
server.get(@metrics_path) { |_req| all_metrics }
|
111
|
+
server.get(@aggregated_metrics_path) { |_req| all_workers_metrics }
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def shutdown
|
116
|
+
if @webrick_server
|
117
|
+
@webrick_server.shutdown
|
118
|
+
@webrick_server = nil
|
119
|
+
end
|
120
|
+
super
|
121
|
+
end
|
122
|
+
|
123
|
+
private
|
124
|
+
|
125
|
+
# For compatiblity because http helper can't support extra_conf option
|
126
|
+
def start_webrick
|
127
|
+
require 'webrick/https'
|
128
|
+
require 'webrick'
|
129
|
+
|
70
130
|
config = {
|
71
131
|
BindAddress: @bind,
|
72
132
|
Port: @port,
|
@@ -74,90 +134,96 @@ module Fluent::Plugin
|
|
74
134
|
Logger: WEBrick::Log.new(STDERR, WEBrick::Log::FATAL),
|
75
135
|
AccessLog: [],
|
76
136
|
}
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
end
|
90
|
-
if @ssl['private_key_path']
|
91
|
-
key = OpenSSL::PKey::RSA.new(File.read(@ssl['private_key_path']))
|
92
|
-
ssl_config[:SSLPrivateKey] = key
|
93
|
-
end
|
94
|
-
ssl_config[:SSLCACertificateFile] = @ssl['ca_path'] if @ssl['ca_path']
|
95
|
-
ssl_config = ssl_config.merge(@ssl['extra_conf'])
|
96
|
-
config = ssl_config.merge(config)
|
137
|
+
if (@ssl['certificate_path'] && @ssl['private_key_path'].nil?) || (@ssl['certificate_path'].nil? && @ssl['private_key_path'])
|
138
|
+
raise RuntimeError.new("certificate_path and private_key_path most both be defined")
|
139
|
+
end
|
140
|
+
|
141
|
+
ssl_config = {
|
142
|
+
SSLEnable: true,
|
143
|
+
SSLCertName: [['CN', 'nobody'], ['DC', 'example']]
|
144
|
+
}
|
145
|
+
|
146
|
+
if @ssl['certificate_path']
|
147
|
+
cert = OpenSSL::X509::Certificate.new(File.read(@ssl['certificate_path']))
|
148
|
+
ssl_config[:SSLCertificate] = cert
|
97
149
|
end
|
150
|
+
|
151
|
+
if @ssl['private_key_path']
|
152
|
+
key = OpenSSL::PKey.read(@ssl['private_key_path'])
|
153
|
+
ssl_config[:SSLPrivateKey] = key
|
154
|
+
end
|
155
|
+
|
156
|
+
ssl_config[:SSLCACertificateFile] = @ssl['ca_path'] if @ssl['ca_path']
|
157
|
+
ssl_config = ssl_config.merge(@ssl['extra_conf']) if @ssl['extra_conf']
|
158
|
+
config = ssl_config.merge(config)
|
159
|
+
|
98
160
|
@log.on_debug do
|
99
161
|
@log.debug("WEBrick conf: #{config}")
|
100
162
|
end
|
101
163
|
|
102
|
-
@
|
103
|
-
@
|
104
|
-
|
105
|
-
|
106
|
-
|
164
|
+
@webrick_server = WEBrick::HTTPServer.new(config)
|
165
|
+
@webrick_server.mount_proc(@metrics_path) do |_req, res|
|
166
|
+
status, header, body = all_metrics
|
167
|
+
res.status = status
|
168
|
+
res['Content-Type'] = header['Content-Type']
|
169
|
+
res.body = body
|
170
|
+
res
|
107
171
|
end
|
108
|
-
end
|
109
172
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
173
|
+
@webrick_server.mount_proc(@aggregated_metrics_path) do |_req, res|
|
174
|
+
status, header, body = all_workers_metrics
|
175
|
+
res.status = status
|
176
|
+
res['Content-Type'] = header['Content-Type']
|
177
|
+
res.body = body
|
178
|
+
res
|
179
|
+
end
|
180
|
+
|
181
|
+
thread_create(:in_prometheus_webrick) do
|
182
|
+
@webrick_server.start
|
114
183
|
end
|
115
|
-
super
|
116
184
|
end
|
117
185
|
|
118
|
-
|
119
|
-
|
120
|
-
|
186
|
+
def all_metrics
|
187
|
+
[200, { 'Content-Type' => ::Prometheus::Client::Formats::Text::CONTENT_TYPE }, ::Prometheus::Client::Formats::Text.marshal(@registry)]
|
188
|
+
rescue => e
|
189
|
+
[500, { 'Content-Type' => 'text/plain' }, e.to_s]
|
190
|
+
end
|
191
|
+
|
192
|
+
def all_workers_metrics
|
193
|
+
full_result = PromMetricsAggregator.new
|
194
|
+
|
195
|
+
send_request_to_each_worker do |resp|
|
196
|
+
if resp.code.to_s == '200'
|
197
|
+
full_result.add_metrics(resp.body)
|
198
|
+
end
|
121
199
|
end
|
122
200
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
201
|
+
[200, { 'Content-Type' => ::Prometheus::Client::Formats::Text::CONTENT_TYPE }, full_result.get_metrics]
|
202
|
+
rescue => e
|
203
|
+
[500, { 'Content-Type' => 'text/plain' }, e.to_s]
|
204
|
+
end
|
205
|
+
|
206
|
+
def send_request_to_each_worker
|
207
|
+
bind = (@bind == '0.0.0.0') ? '127.0.0.1' : @bind
|
208
|
+
[*(@base_port...(@base_port + @num_workers))].each do |worker_port|
|
209
|
+
do_request(host: bind, port: worker_port, secure: @secure) do |http|
|
210
|
+
yield(http.get(@metrics_path))
|
211
|
+
end
|
131
212
|
end
|
132
213
|
end
|
133
214
|
|
134
|
-
|
135
|
-
|
136
|
-
|
215
|
+
# might be replaced by AsyncWrapper if async gem is installed
|
216
|
+
def do_request(host:, port:, secure:)
|
217
|
+
http = Net::HTTP.new(host, port)
|
218
|
+
|
219
|
+
if secure
|
220
|
+
http.use_ssl = true
|
221
|
+
# target is our child process. so it's secure.
|
222
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
137
223
|
end
|
138
224
|
|
139
|
-
|
140
|
-
|
141
|
-
res['Content-Type'] = ::Prometheus::Client::Formats::Text::CONTENT_TYPE
|
142
|
-
|
143
|
-
full_result = PromMetricsAggregator.new
|
144
|
-
fluent_server_ip = @prometheus.bind == '0.0.0.0' ? '127.0.0.1' : @prometheus.bind
|
145
|
-
current_worker = 0
|
146
|
-
while current_worker < @prometheus.num_workers
|
147
|
-
Net::HTTP.start(fluent_server_ip, @prometheus.base_port + current_worker) do |http|
|
148
|
-
req = Net::HTTP::Get.new(@prometheus.metrics_path)
|
149
|
-
result = http.request(req)
|
150
|
-
if result.is_a?(Net::HTTPSuccess)
|
151
|
-
full_result.add_metrics(result.body)
|
152
|
-
end
|
153
|
-
end
|
154
|
-
current_worker += 1
|
155
|
-
end
|
156
|
-
res.body = full_result.get_metrics
|
157
|
-
rescue
|
158
|
-
res.status = 500
|
159
|
-
res['Content-Type'] = 'text/plain'
|
160
|
-
res.body = $!.to_s
|
225
|
+
http.start do
|
226
|
+
yield(http)
|
161
227
|
end
|
162
228
|
end
|
163
229
|
end
|