fluent-plugin-prometheus 1.8.0 → 1.8.5

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
  SHA256:
3
- metadata.gz: 3f98778420f98da85a1325661e897dce930a9eaec03675f3112ca9223a8435a4
4
- data.tar.gz: 864fd85893d2cbe49c2aa5d8e59026405098d9075e54499cbe3efc8e30025a3d
3
+ metadata.gz: 5679e5c8d8872be0448075a8c1e05c395b1f9c06a0267f568a788c77dc12dc62
4
+ data.tar.gz: 786191b3092cf3745ab97425e4aebb4b1cb524c907433d0f4e091dbb6d14b7f9
5
5
  SHA512:
6
- metadata.gz: ae6ec1075cf1fa4ab375a888c0a37c2653cf067e25a87b588ef5b5a332aa090cb1794b9add155314e4b867a188cca55450b064ea04ec99cb9299ad2fcfbde37b
7
- data.tar.gz: c0d269902c7efff6fe7cb153c853fc17eaf9b0a740994ece3701854308fff45af2fa906c17efa2d0af32f882dfdcdd40340c5f3b8ad21a58469655104064a0c1
6
+ metadata.gz: 1b7c49f483ad596641edf01226e4282db10b72dd0117867884d0df4cf6ca0cf23c48e54eab6a2a22ca3ecae845ad8edda6e75d3532853a200b7a57ac8caca423
7
+ data.tar.gz: 344b9a363c49067056c4366f46b6b9f3bddf955e22a0155215158b13420027479c0a5e41da1a86b2baaf71e0b01256d90d0a0c8269c322ebe3616c861ce35a98
@@ -0,0 +1,27 @@
1
+ Release 1.8.5 - 2020/11/24
2
+
3
+ * in_prometheus_monitor: Support USR2 reload
4
+
5
+ Release 1.8.4 - 2020/09/24
6
+
7
+ * in_prometheus_output_monitor: Add gauge_all parameter
8
+
9
+ Release 1.8.3 - 2020/08/24
10
+
11
+ * Fix resourcr leak in async-http based server
12
+
13
+ Release 1.8.2 - 2020/07/17
14
+
15
+ * in_prometheus_output_monitor/in_prometheus_tail_monitor: Support USR2 reload
16
+
17
+ Release 1.8.1 - 2020/07/06
18
+
19
+ * Fix aggregate bug with async-http
20
+
21
+ Release 1.8.0 - 2020/04/17
22
+
23
+ * Use http_server helper
24
+ * Require fluentd v1.9.1 or later
25
+
26
+
27
+ For older releases, see commits on github repository.
data/README.md CHANGED
@@ -124,7 +124,7 @@ Metrics for output
124
124
  - `fluentd_output_status_emit_records`
125
125
  - `fluentd_output_status_write_count`
126
126
  - `fluentd_output_status_rollback_count`
127
- - `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
128
128
  - `fluentd_output_status_slow_flush_count` from fluentd v1.6.0
129
129
 
130
130
  Metrics for buffer
@@ -152,6 +152,7 @@ More configuration parameters:
152
152
 
153
153
  - `<labels>`: additional labels for this metric (optional). See [Labels](#labels)
154
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.
155
156
 
156
157
  ### prometheus_tail_monitor input plugin
157
158
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "fluent-plugin-prometheus"
3
- spec.version = "1.8.0"
3
+ spec.version = "1.8.5"
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.}
@@ -73,6 +73,14 @@ module Fluent::Plugin
73
73
  return
74
74
  end
75
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
+
76
84
  tls_opt = if @ssl && @ssl['enable']
77
85
  ssl_config = {}
78
86
 
@@ -185,7 +193,7 @@ module Fluent::Plugin
185
193
  full_result = PromMetricsAggregator.new
186
194
 
187
195
  send_request_to_each_worker do |resp|
188
- if resp.is_a?(Net::HTTPSuccess)
196
+ if resp.code.to_s == '200'
189
197
  full_result.add_metrics(resp.body)
190
198
  end
191
199
  end
@@ -197,14 +205,14 @@ module Fluent::Plugin
197
205
 
198
206
  def send_request_to_each_worker
199
207
  bind = (@bind == '0.0.0.0') ? '127.0.0.1' : @bind
200
- req = Net::HTTP::Get.new(@metrics_path)
201
208
  [*(@base_port...(@base_port + @num_workers))].each do |worker_port|
202
209
  do_request(host: bind, port: worker_port, secure: @secure) do |http|
203
- yield(http.request(req))
210
+ yield(http.get(@metrics_path))
204
211
  end
205
212
  end
206
213
  end
207
214
 
215
+ # might be replaced by AsyncWrapper if async gem is installed
208
216
  def do_request(host:, port:, secure:)
209
217
  http = Net::HTTP.new(host, port)
210
218
 
@@ -214,7 +222,7 @@ module Fluent::Plugin
214
222
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
215
223
  end
216
224
 
217
- http.start do
225
+ http.start do
218
226
  yield(http)
219
227
  end
220
228
  end
@@ -0,0 +1,47 @@
1
+ require 'async'
2
+
3
+ module Fluent::Plugin
4
+ class PrometheusInput
5
+ module AsyncWrapper
6
+ def do_request(host:, port:, secure:)
7
+ endpoint =
8
+ if secure
9
+ context = OpenSSL::SSL::SSLContext.new
10
+ context.verify_mode = OpenSSL::SSL::VERIFY_NONE
11
+ Async::HTTP::Endpoint.parse("https://#{host}:#{port}", ssl_context: context)
12
+ else
13
+ Async::HTTP::Endpoint.parse("http://#{host}:#{port}")
14
+ end
15
+
16
+ Async::HTTP::Client.open(endpoint) do |client|
17
+ yield(AsyncHttpWrapper.new(client))
18
+ end
19
+ end
20
+
21
+ Response = Struct.new(:code, :body, :headers)
22
+
23
+ class AsyncHttpWrapper
24
+ def initialize(http)
25
+ @http = http
26
+ end
27
+
28
+ def get(path)
29
+ error = nil
30
+ response = Async::Task.current.async {
31
+ begin
32
+ @http.get(path)
33
+ rescue => e # Async::Reactor rescue all error. handle it by itself
34
+ error = e
35
+ end
36
+ }.wait
37
+
38
+ if error
39
+ raise error
40
+ end
41
+
42
+ Response.new(response.status.to_s, response.read || '', response.headers)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -46,19 +46,19 @@ module Fluent::Plugin
46
46
  def start
47
47
  super
48
48
 
49
- @buffer_newest_timekey = @registry.gauge(
49
+ @buffer_newest_timekey = get_gauge(
50
50
  :fluentd_status_buffer_newest_timekey,
51
51
  'Newest timekey in buffer.')
52
- @buffer_oldest_timekey = @registry.gauge(
52
+ @buffer_oldest_timekey = get_gauge(
53
53
  :fluentd_status_buffer_oldest_timekey,
54
54
  'Oldest timekey in buffer.')
55
- buffer_queue_length = @registry.gauge(
55
+ buffer_queue_length = get_gauge(
56
56
  :fluentd_status_buffer_queue_length,
57
57
  'Current buffer queue length.')
58
- buffer_total_queued_size = @registry.gauge(
58
+ buffer_total_queued_size = get_gauge(
59
59
  :fluentd_status_buffer_total_bytes,
60
60
  'Current total size of queued buffers.')
61
- retry_counts = @registry.gauge(
61
+ retry_counts = get_gauge(
62
62
  :fluentd_status_retry_count,
63
63
  'Current retry counts.')
64
64
 
@@ -95,5 +95,13 @@ module Fluent::Plugin
95
95
  type: plugin_info["type"],
96
96
  )
97
97
  end
98
+
99
+ def get_gauge(name, docstring)
100
+ if @registry.exist?(name)
101
+ @registry.get(name)
102
+ else
103
+ @registry.gauge(name, docstring)
104
+ end
105
+ end
98
106
  end
99
107
  end
@@ -1,15 +1,16 @@
1
- require 'fluent/input'
1
+ require 'fluent/plugin/input'
2
2
  require 'fluent/plugin/in_monitor_agent'
3
3
  require 'fluent/plugin/prometheus'
4
4
 
5
5
  module Fluent::Plugin
6
- class PrometheusOutputMonitorInput < Fluent::Input
6
+ class PrometheusOutputMonitorInput < Fluent::Plugin::Input
7
7
  Fluent::Plugin.register_input('prometheus_output_monitor', self)
8
8
  include Fluent::Plugin::PrometheusLabelParser
9
9
 
10
10
  helpers :timer
11
11
 
12
12
  config_param :interval, :time, default: 5
13
+ config_param :gauge_all, :bool, default: true
13
14
  attr_reader :registry
14
15
 
15
16
  MONITOR_IVARS = [
@@ -53,12 +54,9 @@ module Fluent::Plugin
53
54
  @base_labels[key] = expander.expand(value)
54
55
  end
55
56
 
56
- if defined?(Fluent::Plugin) && defined?(Fluent::Plugin::MonitorAgentInput)
57
- # from v0.14.6
58
- @monitor_agent = Fluent::Plugin::MonitorAgentInput.new
59
- else
60
- @monitor_agent = Fluent::MonitorAgentInput.new
61
- end
57
+ @monitor_agent = Fluent::Plugin::MonitorAgentInput.new
58
+
59
+ @gauge_or_counter = @gauge_all ? :gauge : :counter
62
60
  end
63
61
 
64
62
  def start
@@ -66,57 +64,57 @@ module Fluent::Plugin
66
64
 
67
65
  @metrics = {
68
66
  # Buffer metrics
69
- buffer_total_queued_size: @registry.gauge(
67
+ buffer_total_queued_size: get_gauge(
70
68
  :fluentd_output_status_buffer_total_bytes,
71
69
  'Current total size of stage and queue buffers.'),
72
- buffer_stage_length: @registry.gauge(
70
+ buffer_stage_length: get_gauge(
73
71
  :fluentd_output_status_buffer_stage_length,
74
72
  'Current length of stage buffers.'),
75
- buffer_stage_byte_size: @registry.gauge(
73
+ buffer_stage_byte_size: get_gauge(
76
74
  :fluentd_output_status_buffer_stage_byte_size,
77
75
  'Current total size of stage buffers.'),
78
- buffer_queue_length: @registry.gauge(
76
+ buffer_queue_length: get_gauge(
79
77
  :fluentd_output_status_buffer_queue_length,
80
78
  'Current length of queue buffers.'),
81
- buffer_queue_byte_size: @registry.gauge(
79
+ buffer_queue_byte_size: get_gauge(
82
80
  :fluentd_output_status_queue_byte_size,
83
81
  'Current total size of queue buffers.'),
84
- buffer_available_buffer_space_ratios: @registry.gauge(
82
+ buffer_available_buffer_space_ratios: get_gauge(
85
83
  :fluentd_output_status_buffer_available_space_ratio,
86
84
  'Ratio of available space in buffer.'),
87
- buffer_newest_timekey: @registry.gauge(
85
+ buffer_newest_timekey: get_gauge(
88
86
  :fluentd_output_status_buffer_newest_timekey,
89
87
  'Newest timekey in buffer.'),
90
- buffer_oldest_timekey: @registry.gauge(
88
+ buffer_oldest_timekey: get_gauge(
91
89
  :fluentd_output_status_buffer_oldest_timekey,
92
90
  'Oldest timekey in buffer.'),
93
91
 
94
92
  # Output metrics
95
- retry_counts: @registry.gauge(
93
+ retry_counts: get_gauge_or_counter(
96
94
  :fluentd_output_status_retry_count,
97
95
  'Current retry counts.'),
98
- num_errors: @registry.gauge(
96
+ num_errors: get_gauge_or_counter(
99
97
  :fluentd_output_status_num_errors,
100
98
  'Current number of errors.'),
101
- emit_count: @registry.gauge(
99
+ emit_count: get_gauge_or_counter(
102
100
  :fluentd_output_status_emit_count,
103
101
  'Current emit counts.'),
104
- emit_records: @registry.gauge(
102
+ emit_records: get_gauge_or_counter(
105
103
  :fluentd_output_status_emit_records,
106
104
  'Current emit records.'),
107
- write_count: @registry.gauge(
105
+ write_count: get_gauge_or_counter(
108
106
  :fluentd_output_status_write_count,
109
107
  'Current write counts.'),
110
- rollback_count: @registry.gauge(
108
+ rollback_count: get_gauge(
111
109
  :fluentd_output_status_rollback_count,
112
110
  'Current rollback counts.'),
113
- flush_time_count: @registry.gauge(
111
+ flush_time_count: get_gauge_or_counter(
114
112
  :fluentd_output_status_flush_time_count,
115
113
  'Total flush time.'),
116
- slow_flush_count: @registry.gauge(
114
+ slow_flush_count: get_gauge_or_counter(
117
115
  :fluentd_output_status_slow_flush_count,
118
116
  'Current slow flush counts.'),
119
- retry_wait: @registry.gauge(
117
+ retry_wait: get_gauge(
120
118
  :fluentd_output_status_retry_wait,
121
119
  'Current retry wait'),
122
120
  }
@@ -162,14 +160,22 @@ module Fluent::Plugin
162
160
 
163
161
  monitor_info.each do |name, metric|
164
162
  if info[name]
165
- metric.set(label, info[name])
163
+ if metric.is_a?(::Prometheus::Client::Gauge)
164
+ metric.set(label, info[name])
165
+ elsif metric.is_a?(::Prometheus::Client::Counter)
166
+ metric.increment(label, info[name] - metric.get(label))
167
+ end
166
168
  end
167
169
  end
168
170
 
169
171
  if info['instance_variables']
170
172
  instance_vars_info.each do |name, metric|
171
173
  if info['instance_variables'][name]
172
- metric.set(label, info['instance_variables'][name])
174
+ if metric.is_a?(::Prometheus::Client::Gauge)
175
+ metric.set(label, info['instance_variables'][name])
176
+ elsif metric.is_a?(::Prometheus::Client::Counter)
177
+ metric.increment(label, info['instance_variables'][name] - metric.get(label))
178
+ end
173
179
  end
174
180
  end
175
181
  end
@@ -198,5 +204,21 @@ module Fluent::Plugin
198
204
  type: plugin_info["type"],
199
205
  )
200
206
  end
207
+
208
+ def get_gauge(name, docstring)
209
+ if @registry.exist?(name)
210
+ @registry.get(name)
211
+ else
212
+ @registry.gauge(name, docstring)
213
+ end
214
+ end
215
+
216
+ def get_gauge_or_counter(name, docstring)
217
+ if @registry.exist?(name)
218
+ @registry.get(name)
219
+ else
220
+ @registry.public_send(@gauge_or_counter, name, docstring)
221
+ end
222
+ end
201
223
  end
202
224
  end
@@ -38,22 +38,17 @@ module Fluent::Plugin
38
38
  @base_labels[key] = expander.expand(value)
39
39
  end
40
40
 
41
- if defined?(Fluent::Plugin) && defined?(Fluent::Plugin::MonitorAgentInput)
42
- # from v0.14.6
43
- @monitor_agent = Fluent::Plugin::MonitorAgentInput.new
44
- else
45
- @monitor_agent = Fluent::MonitorAgentInput.new
46
- end
41
+ @monitor_agent = Fluent::Plugin::MonitorAgentInput.new
47
42
  end
48
43
 
49
44
  def start
50
45
  super
51
46
 
52
47
  @metrics = {
53
- position: @registry.gauge(
48
+ position: get_gauge(
54
49
  :fluentd_tail_file_position,
55
50
  'Current position of file.'),
56
- inode: @registry.gauge(
51
+ inode: get_gauge(
57
52
  :fluentd_tail_file_inode,
58
53
  'Current inode of file.'),
59
54
  }
@@ -91,5 +86,13 @@ module Fluent::Plugin
91
86
  path: path,
92
87
  )
93
88
  end
89
+
90
+ def get_gauge(name, docstring)
91
+ if @registry.exist?(name)
92
+ @registry.get(name)
93
+ else
94
+ @registry.gauge(name, docstring)
95
+ end
96
+ end
94
97
  end
95
98
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-prometheus
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.8.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masahiro Sano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-21 00:00:00.000000000 Z
11
+ date: 2020-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
@@ -110,6 +110,7 @@ files:
110
110
  - ".gitignore"
111
111
  - ".rspec"
112
112
  - ".travis.yml"
113
+ - ChangeLog
113
114
  - Gemfile
114
115
  - LICENSE
115
116
  - README.md
@@ -117,6 +118,7 @@ files:
117
118
  - fluent-plugin-prometheus.gemspec
118
119
  - lib/fluent/plugin/filter_prometheus.rb
119
120
  - lib/fluent/plugin/in_prometheus.rb
121
+ - lib/fluent/plugin/in_prometheus/async_wrapper.rb
120
122
  - lib/fluent/plugin/in_prometheus_monitor.rb
121
123
  - lib/fluent/plugin/in_prometheus_output_monitor.rb
122
124
  - lib/fluent/plugin/in_prometheus_tail_monitor.rb