fluent-plugin-prometheus 0.1.3 → 0.2.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 +27 -3
- data/fluent-plugin-prometheus.gemspec +1 -1
- data/lib/fluent/plugin/prometheus.rb +39 -3
- data/misc/prometheus.yaml +1 -1
- data/spec/fluent/plugin/filter_prometheus_spec.rb +1 -1
- data/spec/fluent/plugin/out_prometheus_spec.rb +1 -1
- data/spec/fluent/plugin/shared.rb +20 -0
- metadata +2 -3
- data/misc/prometheus-old-format.conf +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5dbca01329f7efc77c5fa44288e017857e3c5a3a
|
4
|
+
data.tar.gz: a5e6e68b51cd13af4ba048f070b69b92e831bf89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb2b9a310bdb2f74a8bfd3f6fdde9379f75cefcb98a36c32083ddf97019a6bf0efccb7592d9c62af7fd4bdf55261407573e984775ee432f393d83612f25a8464
|
7
|
+
data.tar.gz: 6033c960888b9989fbebced596a949c9333595a9df6376a24fee8c91723c898dbe365693d62c9b179e86e08a04551a722b3c6c08626560aa3197656f34f144c8
|
data/README.md
CHANGED
@@ -217,6 +217,30 @@ If key is empty, the metric values is treated as 1, so the counter increments by
|
|
217
217
|
- `key`: key name of record for instrumentation (required)
|
218
218
|
- `<labels>`: additional labels for this metric (optional). See [Labels](#Labels)
|
219
219
|
|
220
|
+
### histogram type
|
221
|
+
|
222
|
+
```
|
223
|
+
<metric>
|
224
|
+
name message_foo
|
225
|
+
type histogram
|
226
|
+
desc The histogram of foo in message.
|
227
|
+
key foo
|
228
|
+
buckets 0.1, 1, 5, 10
|
229
|
+
<labels>
|
230
|
+
tag ${tag}
|
231
|
+
host ${hostname}
|
232
|
+
foo bar
|
233
|
+
</labels>
|
234
|
+
</metric>
|
235
|
+
```
|
236
|
+
|
237
|
+
- `name`: metric name (required)
|
238
|
+
- `type`: metric type (required)
|
239
|
+
- `desc`: description of metric (required)
|
240
|
+
- `key`: key name of record for instrumentation (required)
|
241
|
+
- `buckets`: buckets of record for instrumentation (optional)
|
242
|
+
- `<labels>`: additional labels for this metric (optional). See [Labels](#Labels)
|
243
|
+
|
220
244
|
## Labels
|
221
245
|
|
222
246
|
See [Prometheus Data Model](http://prometheus.io/docs/concepts/data_model/) first.
|
@@ -280,7 +304,7 @@ In this case, `message_foo_counter` has `tag`, `hostname`, `key` and `data_type`
|
|
280
304
|
|
281
305
|
## Try plugin with nginx
|
282
306
|
|
283
|
-
Checkout
|
307
|
+
Checkout repository and setup.
|
284
308
|
|
285
309
|
```
|
286
310
|
$ git clone git://github.com/kazegusuri/fluent-plugin-prometheus
|
@@ -291,8 +315,8 @@ $ bundle install --path vendor/bundle
|
|
291
315
|
Download pre-compiled prometheus binary and start it. It listens on 9090.
|
292
316
|
|
293
317
|
```
|
294
|
-
$ wget https://github.com/prometheus/prometheus/releases/download/0.
|
295
|
-
$ ./prometheus-0.
|
318
|
+
$ wget https://github.com/prometheus/prometheus/releases/download/v1.0.1/prometheus-1.0.1.linux-amd64.tar.gz -O - | tar zxf -
|
319
|
+
$ ./prometheus-1.0.1.linux-amd64/prometheus -config.file=./misc/prometheus.yaml -storage.local.path=./prometheus/metrics
|
296
320
|
```
|
297
321
|
|
298
322
|
Install Nginx for sample metrics. It listens on 80 and 9999.
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "fluent-plugin-prometheus"
|
3
|
-
spec.version = "0.
|
3
|
+
spec.version = "0.2.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.}
|
@@ -34,8 +34,10 @@ module Fluent
|
|
34
34
|
metrics << Fluent::Prometheus::Gauge.new(element, registry, labels)
|
35
35
|
when 'counter'
|
36
36
|
metrics << Fluent::Prometheus::Counter.new(element, registry, labels)
|
37
|
+
when 'histogram'
|
38
|
+
metrics << Fluent::Prometheus::Histogram.new(element, registry, labels)
|
37
39
|
else
|
38
|
-
raise ConfigError, "type option must be 'counter', 'gauge' or '
|
40
|
+
raise ConfigError, "type option must be 'counter', 'gauge', 'summary' or 'histogram'"
|
39
41
|
end
|
40
42
|
}
|
41
43
|
metrics
|
@@ -46,7 +48,13 @@ module Fluent
|
|
46
48
|
if defined?(Fluent::Filter) # for v0.12, built-in PlaceholderExpander
|
47
49
|
begin
|
48
50
|
require 'fluent/plugin/filter_record_transformer'
|
49
|
-
|
51
|
+
if defined?(Fluent::Plugin::RecordTransformerFilter::PlaceholderExpander)
|
52
|
+
# for v0.14
|
53
|
+
return Fluent::Plugin::RecordTransformerFilter::PlaceholderExpander.new(log: log)
|
54
|
+
else
|
55
|
+
# for v0.12
|
56
|
+
return Fluent::RecordTransformerFilter::PlaceholderExpander.new(log: log)
|
57
|
+
end
|
50
58
|
rescue LoadError => e
|
51
59
|
raise ConfigError, "cannot find filter_record_transformer plugin: #{e.message}"
|
52
60
|
end
|
@@ -188,7 +196,35 @@ module Fluent
|
|
188
196
|
|
189
197
|
def instrument(record, expander, placeholders)
|
190
198
|
if record[@key]
|
191
|
-
@summary.
|
199
|
+
@summary.observe(labels(record, expander, placeholders), record[@key])
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
class Histogram < Metric
|
205
|
+
def initialize(element, registry, labels)
|
206
|
+
super
|
207
|
+
if @key.nil?
|
208
|
+
raise ConfigError, "histogram metric requires 'key' option"
|
209
|
+
end
|
210
|
+
|
211
|
+
begin
|
212
|
+
if element['buckets']
|
213
|
+
buckets = element['buckets'].split(/,/).map(&:strip).map do |e|
|
214
|
+
e[/\A\d+.\d+\Z/] ? e.to_f : e.to_i
|
215
|
+
end
|
216
|
+
@histogram = registry.histogram(element['name'].to_sym, element['desc'], {}, buckets)
|
217
|
+
else
|
218
|
+
@histogram = registry.histogram(element['name'].to_sym, element['desc'])
|
219
|
+
end
|
220
|
+
rescue ::Prometheus::Client::Registry::AlreadyRegisteredError
|
221
|
+
@histogram = Fluent::Prometheus::Metric.get(registry, element['name'].to_sym, :histogram, element['desc'])
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
def instrument(record, expander, placeholders)
|
226
|
+
if record[@key]
|
227
|
+
@histogram.observe(labels(record, expander, placeholders), record[@key])
|
192
228
|
end
|
193
229
|
end
|
194
230
|
end
|
data/misc/prometheus.yaml
CHANGED
@@ -12,7 +12,7 @@ describe Fluent::PrometheusFilter do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
describe '#run' do
|
15
|
-
let(:message) { {"foo" => 100, "bar" => 100, "baz" => 100} }
|
15
|
+
let(:message) { {"foo" => 100, "bar" => 100, "baz" => 100, "qux" => 10} }
|
16
16
|
let(:es) { driver.run { driver.emit(message, Time.now) }.filtered }
|
17
17
|
|
18
18
|
context 'simple config' do
|
@@ -12,7 +12,7 @@ describe Fluent::PrometheusOutput do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
describe '#run' do
|
15
|
-
let(:message) { {"foo" => 100, "bar" => 100, "baz" => 100} }
|
15
|
+
let(:message) { {"foo" => 100, "bar" => 100, "baz" => 100, "qux" => 10} }
|
16
16
|
let(:es) { driver.run { driver.emit(message, Time.now) } }
|
17
17
|
|
18
18
|
context 'simple config' do
|
@@ -42,6 +42,16 @@ FULL_CONFIG = BASE_CONFIG + %[
|
|
42
42
|
key foo3
|
43
43
|
</labels>
|
44
44
|
</metric>
|
45
|
+
<metric>
|
46
|
+
name full_qux
|
47
|
+
type histogram
|
48
|
+
desc Something qux.
|
49
|
+
key qux
|
50
|
+
buckets 0.1, 1, 5, 10
|
51
|
+
<labels>
|
52
|
+
key foo4
|
53
|
+
</labels>
|
54
|
+
</metric>
|
45
55
|
<labels>
|
46
56
|
test_key test_value
|
47
57
|
</labels>
|
@@ -83,6 +93,7 @@ shared_context 'full_config' do
|
|
83
93
|
let(:counter) { registry.get(:full_foo) }
|
84
94
|
let(:gauge) { registry.get(:full_bar) }
|
85
95
|
let(:summary) { registry.get(:full_baz) }
|
96
|
+
let(:histogram) { registry.get(:full_qux) }
|
86
97
|
end
|
87
98
|
|
88
99
|
shared_context 'placeholder_config' do
|
@@ -139,12 +150,14 @@ shared_examples_for 'output configuration' do
|
|
139
150
|
end
|
140
151
|
end
|
141
152
|
|
153
|
+
emit_count = 0
|
142
154
|
shared_examples_for 'instruments record' do
|
143
155
|
context 'full config' do
|
144
156
|
include_context 'full_config'
|
145
157
|
|
146
158
|
before :each do
|
147
159
|
es
|
160
|
+
emit_count += 1
|
148
161
|
end
|
149
162
|
|
150
163
|
it 'adds all metrics' do
|
@@ -154,6 +167,7 @@ shared_examples_for 'instruments record' do
|
|
154
167
|
expect(counter).to be_kind_of(::Prometheus::Client::Metric)
|
155
168
|
expect(gauge).to be_kind_of(::Prometheus::Client::Metric)
|
156
169
|
expect(summary).to be_kind_of(::Prometheus::Client::Metric)
|
170
|
+
expect(histogram).to be_kind_of(::Prometheus::Client::Metric)
|
157
171
|
end
|
158
172
|
|
159
173
|
it 'instruments counter metric' do
|
@@ -171,6 +185,12 @@ shared_examples_for 'instruments record' do
|
|
171
185
|
expect(summary.get({test_key: 'test_value', key: 'foo3'})).to be_kind_of(Hash)
|
172
186
|
expect(summary.get({test_key: 'test_value', key: 'foo3'})[0.99]).to eq(100)
|
173
187
|
end
|
188
|
+
|
189
|
+
it 'instruments histogram metric' do
|
190
|
+
expect(histogram.type).to eq(:histogram)
|
191
|
+
expect(histogram.get({test_key: 'test_value', key: 'foo4'})).to be_kind_of(Hash)
|
192
|
+
expect(histogram.get({test_key: 'test_value', key: 'foo4'})[10]).to eq(emit_count)
|
193
|
+
end
|
174
194
|
end
|
175
195
|
|
176
196
|
context 'placeholder config' 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: 0.
|
4
|
+
version: 0.2.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: 2016-
|
11
|
+
date: 2016-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|
@@ -118,7 +118,6 @@ files:
|
|
118
118
|
- lib/fluent/plugin/prometheus.rb
|
119
119
|
- misc/fluentd_sample.conf
|
120
120
|
- misc/nginx_proxy.conf
|
121
|
-
- misc/prometheus-old-format.conf
|
122
121
|
- misc/prometheus.yaml
|
123
122
|
- spec/fluent/plugin/filter_prometheus_spec.rb
|
124
123
|
- spec/fluent/plugin/out_prometheus_spec.rb
|