fluent-plugin-prometheus 1.2.1 → 1.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 64ed448a556ffbc5fda04297363a53663dc2acff960d358bb24b07e227b99b3a
4
- data.tar.gz: 2ad3f13b35c60b0fad6664831e9d4edcacfcf963a3a819c658aad761bc64af2f
3
+ metadata.gz: 274c9ef3f67ca084c8b46d6a24ca97ce8313d2ade4409426dc2bb664ec227f31
4
+ data.tar.gz: 1c3cc72e17e834cf5144315086856bc8a8394a1a893771f7521e0a0fd4adf73f
5
5
  SHA512:
6
- metadata.gz: cb6b43bf8e18dea2ff324a1a75738b51513c652ca3afdea8bf941f5d56e0b44028d19726daef5ee704070597e243e0c5262db1edaf6027adb3f1a2f6baf3c76a
7
- data.tar.gz: 0dd07480d6a1a4db6345e14727f932b1c2ce09ce9683f01f4fe4c3e008c608742ef47a68aca27371f182dc1b8cd995420bef3a4d666abe6ff0ec6ed218513916
6
+ metadata.gz: 791e3bf0e513d98d32f0bb8a0f936e305f373ae2706fd9ad6bd3cdd12eb9adcd288d811ea3bcc9eb06c50b7eb583ec5edda3fb52751f7def52252c1174780407
7
+ data.tar.gz: 2aa16a95bedb91f4f04bac51a8fe96ee540aefe13532429d12803f97f0537e9fd3c10bb54a37c8145f8a58fe0e06e7975d7e99e1a8addb686eb12311ab9951c5
data/README.md CHANGED
@@ -42,8 +42,8 @@ See [sample configuration](./misc/fluentd_sample.conf), or try [tutorial](#try-p
42
42
 
43
43
  ### prometheus input plugin
44
44
 
45
- You have to configure this plugin to expose metrics collected by other promtheus plugins.
46
- This plugin provides a metrics HTTP endpoint to be scraped by a prometheus server on 24231/tcp(default).
45
+ You have to configure this plugin to expose metrics collected by other Prometheus plugins.
46
+ This plugin provides a metrics HTTP endpoint to be scraped by a Prometheus server on 24231/tcp(default).
47
47
 
48
48
  With following configuration, you can access http://localhost:24231/metrics on a server where fluentd running.
49
49
 
@@ -56,7 +56,7 @@ With following configuration, you can access http://localhost:24231/metrics on a
56
56
  More configuration parameters:
57
57
 
58
58
  - `bind`: binding interface (default: '0.0.0.0')
59
- - `port`: listen port (defaut: 24231)
59
+ - `port`: listen port (default: 24231)
60
60
  - `metrics_path`: metrics HTTP endpoint (default: /metrics)
61
61
 
62
62
  When using multiple workers, each worker binds to port + `fluent_worker_id`.
@@ -224,6 +224,8 @@ In output plugin style:
224
224
 
225
225
  With above configuration, the plugin collects a metric named `message_foo_counter` from key `foo` of each records.
226
226
 
227
+ You can access nested keys in records via dot or bracket notation (https://docs.fluentd.org/v1.0/articles/api-plugin-helper-record_accessor#syntax), for example: `$.kubernetes.namespace`, `$['key1'][0]['key2']`. The record accessor is enable only if the value starts with `$.` or `$[`.
228
+
227
229
  See Supported Metric Type and Labels for more configuration parameters.
228
230
 
229
231
  ## Supported Metric Types
@@ -350,12 +352,12 @@ Reserved placeholders are:
350
352
  - `${hostname}`: hostname
351
353
  - `${worker_id}`: fluent worker id
352
354
  - `${tag}`: tag name
353
- - only availabe in prometheus output/filter plugin
355
+ - only available in Prometheus output/filter plugin
354
356
 
355
357
 
356
358
  ### top-level labels and labels inside metric
357
359
 
358
- Prometheus output/filter plugin can have multiple metric section. Top-level labels section spcifies labels for all metrics. Labels section insede metric section specifis labels for the metric. Both are specified, labels are merged.
360
+ Prometheus output/filter plugin can have multiple metric section. Top-level labels section specifies labels for all metrics. Labels section inside metric section specifies labels for the metric. Both are specified, labels are merged.
359
361
 
360
362
  ```
361
363
  <filter message>
@@ -399,7 +401,7 @@ $ cd fluent-plugin-prometheus
399
401
  $ bundle install --path vendor/bundle
400
402
  ```
401
403
 
402
- Download pre-compiled prometheus binary and start it. It listens on 9090.
404
+ Download pre-compiled Prometheus binary and start it. It listens on 9090.
403
405
 
404
406
  ```
405
407
  $ wget https://github.com/prometheus/prometheus/releases/download/v1.5.2/prometheus-1.5.2.linux-amd64.tar.gz -O - | tar zxf -
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "fluent-plugin-prometheus"
3
- spec.version = "1.2.1"
3
+ spec.version = "1.3.0"
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.}
@@ -36,6 +36,10 @@ module Fluent
36
36
  conf.elements.select { |element|
37
37
  element.name == 'metric'
38
38
  }.each { |element|
39
+ if element.has_key?('key') && (element['key'].start_with?('$.') || element['key'].start_with?('$['))
40
+ value = element['key']
41
+ element['key'] = PluginHelper::RecordAccessor::Accessor.new(value)
42
+ end
39
43
  case element['type']
40
44
  when 'summary'
41
45
  metrics << Fluent::Plugin::Prometheus::Summary.new(element, registry, labels)
@@ -147,8 +151,13 @@ module Fluent
147
151
  end
148
152
 
149
153
  def instrument(record, expander, placeholders)
150
- if record[@key]
151
- @gauge.set(labels(record, expander, placeholders), record[@key])
154
+ if @key.is_a?(String)
155
+ value = record[@key]
156
+ else
157
+ value = @key.call(record)
158
+ end
159
+ if value
160
+ @gauge.set(labels(record, expander, placeholders), value)
152
161
  end
153
162
  end
154
163
  end
@@ -165,7 +174,13 @@ module Fluent
165
174
 
166
175
  def instrument(record, expander, placeholders)
167
176
  # use record value of the key if key is specified, otherwise just increment
168
- value = @key ? record[@key] : 1
177
+ if @key.nil?
178
+ value = 1
179
+ elsif @key.is_a?(String)
180
+ value = record[@key]
181
+ else
182
+ value = @key.call(record)
183
+ end
169
184
 
170
185
  # ignore if record value is nil
171
186
  return if value.nil?
@@ -189,8 +204,13 @@ module Fluent
189
204
  end
190
205
 
191
206
  def instrument(record, expander, placeholders)
192
- if record[@key]
193
- @summary.observe(labels(record, expander, placeholders), record[@key])
207
+ if @key.is_a?(String)
208
+ value = record[@key]
209
+ else
210
+ value = @key.call(record)
211
+ end
212
+ if value
213
+ @summary.observe(labels(record, expander, placeholders), value)
194
214
  end
195
215
  end
196
216
  end
@@ -217,8 +237,13 @@ module Fluent
217
237
  end
218
238
 
219
239
  def instrument(record, expander, placeholders)
220
- if record[@key]
221
- @histogram.observe(labels(record, expander, placeholders), record[@key])
240
+ if @key.is_a?(String)
241
+ value = record[@key]
242
+ else
243
+ value = @key.call(record)
244
+ end
245
+ if value
246
+ @histogram.observe(labels(record, expander, placeholders), value)
222
247
  end
223
248
  end
224
249
  end
@@ -52,6 +52,24 @@ FULL_CONFIG = BASE_CONFIG + %[
52
52
  key foo4
53
53
  </labels>
54
54
  </metric>
55
+ <metric>
56
+ name full_accessor1
57
+ type summary
58
+ desc Something with accessor.
59
+ key $.foo
60
+ <labels>
61
+ key foo5
62
+ </labels>
63
+ </metric>
64
+ <metric>
65
+ name full_accessor2
66
+ type counter
67
+ desc Something with accessor.
68
+ key $.foo
69
+ <labels>
70
+ key foo6
71
+ </labels>
72
+ </metric>
55
73
  <labels>
56
74
  test_key test_value
57
75
  </labels>
@@ -110,6 +128,8 @@ shared_context 'full_config' do
110
128
  let(:gauge) { registry.get(:full_bar) }
111
129
  let(:summary) { registry.get(:full_baz) }
112
130
  let(:histogram) { registry.get(:full_qux) }
131
+ let(:summary_with_accessor) { registry.get(:full_accessor1) }
132
+ let(:counter_with_accessor) { registry.get(:full_accessor2) }
113
133
  end
114
134
 
115
135
  shared_context 'placeholder_config' do
@@ -192,15 +212,20 @@ shared_examples_for 'instruments record' do
192
212
  expect(registry.metrics.map(&:name)).to include(:full_foo)
193
213
  expect(registry.metrics.map(&:name)).to include(:full_bar)
194
214
  expect(registry.metrics.map(&:name)).to include(:full_baz)
215
+ expect(registry.metrics.map(&:name)).to include(:full_accessor1)
216
+ expect(registry.metrics.map(&:name)).to include(:full_accessor2)
195
217
  expect(counter).to be_kind_of(::Prometheus::Client::Metric)
196
218
  expect(gauge).to be_kind_of(::Prometheus::Client::Metric)
197
219
  expect(summary).to be_kind_of(::Prometheus::Client::Metric)
220
+ expect(summary_with_accessor).to be_kind_of(::Prometheus::Client::Metric)
221
+ expect(counter_with_accessor).to be_kind_of(::Prometheus::Client::Metric)
198
222
  expect(histogram).to be_kind_of(::Prometheus::Client::Metric)
199
223
  end
200
224
 
201
225
  it 'instruments counter metric' do
202
226
  expect(counter.type).to eq(:counter)
203
227
  expect(counter.get({test_key: 'test_value', key: 'foo1'})).to be_kind_of(Numeric)
228
+ expect(counter_with_accessor.get({test_key: 'test_value', key: 'foo6'})).to be_kind_of(Numeric)
204
229
  end
205
230
 
206
231
  it 'instruments gauge metric' do
@@ -212,6 +237,7 @@ shared_examples_for 'instruments record' do
212
237
  expect(summary.type).to eq(:summary)
213
238
  expect(summary.get({test_key: 'test_value', key: 'foo3'})).to be_kind_of(Hash)
214
239
  expect(summary.get({test_key: 'test_value', key: 'foo3'})[0.99]).to eq(100)
240
+ expect(summary_with_accessor.get({test_key: 'test_value', key: 'foo5'})[0.99]).to eq(100)
215
241
  end
216
242
 
217
243
  it 'instruments histogram metric' do
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.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masahiro Sano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-10 00:00:00.000000000 Z
11
+ date: 2019-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd