fluent-plugin-prometheus-thread 0.1.3
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 +7 -0
- data/.gitignore +16 -0
- data/.rspec +2 -0
- data/.travis.yml +15 -0
- data/Gemfile +4 -0
- data/Gemfile.fluentd.0.10 +4 -0
- data/Gemfile.fluentd.0.12 +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +349 -0
- data/Rakefile +7 -0
- data/fluent-plugin-prometheus.gemspec +22 -0
- data/lib/fluent/plugin/filter_prometheus.rb +24 -0
- data/lib/fluent/plugin/in_prometheus.rb +62 -0
- data/lib/fluent/plugin/in_prometheus_monitor.rb +101 -0
- data/lib/fluent/plugin/out_prometheus.rb +25 -0
- data/lib/fluent/plugin/prometheus.rb +196 -0
- data/misc/fluentd_sample.conf +135 -0
- data/misc/nginx_proxy.conf +22 -0
- data/misc/prometheus-old-format.conf +10 -0
- data/misc/prometheus.yaml +8 -0
- data/spec/fluent/plugin/filter_prometheus_spec.rb +34 -0
- data/spec/fluent/plugin/out_prometheus_spec.rb +30 -0
- data/spec/fluent/plugin/prometheus_spec.rb +76 -0
- data/spec/fluent/plugin/shared.rb +210 -0
- data/spec/spec_helper.rb +8 -0
- metadata +159 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0e0f8c37c6f5e65489176cfc8c2228c3b90d2384
|
4
|
+
data.tar.gz: 2bd0ade045ace6327dc83abdf9d6cace4fc12d3a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 97196f40a5b00444a3b790ec278d3fe451daaf51a0e166cc9cd701ab8bd337cfff74e63356a7a312ad6db06fc1e563b8dd798c19f6a2d7d07529cfb438827a07
|
7
|
+
data.tar.gz: a5a75cd17532ce7daf36e34f313736b3b230b978302cc385d6bd51256c40895153f887346b16cdadcec000a9670956af357777aeb620c5d64e1cc1045726a27f
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Masahiro Sano
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,349 @@
|
|
1
|
+
# fluent-plugin-prometheus, a plugin for [Fluentd](http://fluentd.org)
|
2
|
+
|
3
|
+
[](https://travis-ci.org/kazegusuri/fluent-plugin-prometheus)
|
4
|
+
|
5
|
+
A fluent plugin that instruments metrics from records and exposes them via web interface. Intended to be used together with a [Prometheus server](https://github.com/prometheus/prometheus).
|
6
|
+
|
7
|
+
If you are using Fluentd v0.10, you have to explicitly install [fluent-plugin-record-reformer](https://github.com/sonots/fluent-plugin-record-reformer) together. With Fluentd v0.12 or v0.14, there is no additional dependency.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'fluent-plugin-prometheus'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install fluent-plugin-prometheus
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
fluentd-plugin-prometheus includes 4 plugins.
|
28
|
+
|
29
|
+
- `prometheus` input plugin
|
30
|
+
- `prometheus_monitor` input plugin
|
31
|
+
- `prometheus` output plugin
|
32
|
+
- `prometheus` filter plugin
|
33
|
+
|
34
|
+
See [sample configuration](./misc/fluentd_sample.conf), or try [tutorial](#try-plugin-with-nginx).
|
35
|
+
|
36
|
+
### prometheus input plugin
|
37
|
+
|
38
|
+
You have to configure this plugin to expose metrics collected by other promtheus plugins.
|
39
|
+
This plugin provides a metrics HTTP endpoint to be scraped by a prometheus server on 24231/tcp(default).
|
40
|
+
|
41
|
+
With following configuration, you can access http://localhost:24231/metrics on a server where fluentd running.
|
42
|
+
|
43
|
+
```
|
44
|
+
<source>
|
45
|
+
type prometheus
|
46
|
+
</source>
|
47
|
+
```
|
48
|
+
|
49
|
+
More configuration parameters:
|
50
|
+
|
51
|
+
- `bind`: binding interface (default: '0.0.0.0')
|
52
|
+
- `port`: listen port (defaut: 24231)
|
53
|
+
- `metrics_path`: metrics HTTP endpoint (default: /metrics)
|
54
|
+
|
55
|
+
### prometheus_monitor input plugin
|
56
|
+
|
57
|
+
This plugin collects internal metrics in Fluentd. The metrics are similar to/part of [monitor_agent](http://docs.fluentd.org/articles/monitoring#monitoring-agent).
|
58
|
+
|
59
|
+
Current exposed metrics:
|
60
|
+
|
61
|
+
- `buffere_queue_length` of each BufferedOutput plugins
|
62
|
+
- `buffer_total_queued_size` of each BufferedOutput plugins
|
63
|
+
- `retry_count` of each BufferedOutput plugins
|
64
|
+
|
65
|
+
With following configuration, those metrics are collected.
|
66
|
+
|
67
|
+
<source>
|
68
|
+
type prometheus_monitor
|
69
|
+
</source>
|
70
|
+
|
71
|
+
More configuration parameters:
|
72
|
+
|
73
|
+
- `<labels>`: additional labels for this metric (optional). See [Labels](#Labels)
|
74
|
+
- `interval`: interval to update monitor_agent information in seconds (default: 5)
|
75
|
+
|
76
|
+
### prometheus output/filter plugin
|
77
|
+
|
78
|
+
Both output/filter plugins instrument metrics from records. Both plugins have no impact against values of each records, just read.
|
79
|
+
|
80
|
+
Assuming you have following configuration and receiving message,
|
81
|
+
|
82
|
+
```
|
83
|
+
<match message>
|
84
|
+
type stdout
|
85
|
+
</match>
|
86
|
+
```
|
87
|
+
|
88
|
+
```
|
89
|
+
message {
|
90
|
+
"foo": 100,
|
91
|
+
"bar": 200,
|
92
|
+
"baz": 300
|
93
|
+
}
|
94
|
+
```
|
95
|
+
|
96
|
+
In filter plugin style,
|
97
|
+
|
98
|
+
```
|
99
|
+
<filter message>
|
100
|
+
type prometheus
|
101
|
+
<metric>
|
102
|
+
name message_foo_counter
|
103
|
+
type counter
|
104
|
+
desc The total number of foo in message.
|
105
|
+
key foo
|
106
|
+
</metric>
|
107
|
+
</filter>
|
108
|
+
|
109
|
+
<match message>
|
110
|
+
type stdout
|
111
|
+
</match>
|
112
|
+
```
|
113
|
+
|
114
|
+
In output plugin style:
|
115
|
+
|
116
|
+
```
|
117
|
+
<filter message>
|
118
|
+
type prometheus
|
119
|
+
<metric>
|
120
|
+
name message_foo_counter
|
121
|
+
type counter
|
122
|
+
desc The total number of foo in message.
|
123
|
+
key foo
|
124
|
+
</metric>
|
125
|
+
</filter>
|
126
|
+
|
127
|
+
<match message>
|
128
|
+
type copy
|
129
|
+
<store>
|
130
|
+
type prometheus
|
131
|
+
<metric>
|
132
|
+
name message_foo_counter
|
133
|
+
type counter
|
134
|
+
desc The total number of foo in message.
|
135
|
+
key foo
|
136
|
+
</metric>
|
137
|
+
</store>
|
138
|
+
<store>
|
139
|
+
type stdout
|
140
|
+
</store>
|
141
|
+
</match>
|
142
|
+
```
|
143
|
+
|
144
|
+
With above configuration, the plugin collects a metric named `message_foo_counter` from key `foo` of each records.
|
145
|
+
|
146
|
+
See Supported Metric Type and Labels for more configuration parameters.
|
147
|
+
|
148
|
+
## Supported Metric Types
|
149
|
+
|
150
|
+
For details of each metric type, see [Prometheus documentation](http://prometheus.io/docs/concepts/metric_types/). Also see [metric name guide](http://prometheus.io/docs/practices/naming/).
|
151
|
+
|
152
|
+
### counter type
|
153
|
+
|
154
|
+
```
|
155
|
+
<metric>
|
156
|
+
name message_foo_counter
|
157
|
+
type counter
|
158
|
+
desc The total number of foo in message.
|
159
|
+
key foo
|
160
|
+
<labels>
|
161
|
+
tag ${tag}
|
162
|
+
host ${hostname}
|
163
|
+
foo bar
|
164
|
+
</labels>
|
165
|
+
</metric>
|
166
|
+
```
|
167
|
+
|
168
|
+
- `name`: metric name (required)
|
169
|
+
- `type`: metric type (required)
|
170
|
+
- `desc`: description of this metric (required)
|
171
|
+
- `key`: key name of record for instrumentation (**optional**)
|
172
|
+
- `<labels>`: additional labels for this metric (optional). See [Labels](#Labels)
|
173
|
+
|
174
|
+
If key is empty, the metric values is treated as 1, so the counter increments by 1 on each record regardless of contents of the record.
|
175
|
+
|
176
|
+
### gauge type
|
177
|
+
|
178
|
+
```
|
179
|
+
<metric>
|
180
|
+
name message_foo_gauge
|
181
|
+
type gauge
|
182
|
+
desc The total number of foo in message.
|
183
|
+
key foo
|
184
|
+
<labels>
|
185
|
+
tag ${tag}
|
186
|
+
host ${hostname}
|
187
|
+
foo bar
|
188
|
+
</labels>
|
189
|
+
</metric>
|
190
|
+
```
|
191
|
+
|
192
|
+
- `name`: metric name (required)
|
193
|
+
- `type`: metric type (required)
|
194
|
+
- `desc`: description of metric (required)
|
195
|
+
- `key`: key name of record for instrumentation (required)
|
196
|
+
- `<labels>`: additional labels for this metric (optional). See [Labels](#Labels)
|
197
|
+
|
198
|
+
### summary type
|
199
|
+
|
200
|
+
```
|
201
|
+
<metric>
|
202
|
+
name message_foo
|
203
|
+
type summary
|
204
|
+
desc The summary of foo in message.
|
205
|
+
key foo
|
206
|
+
<labels>
|
207
|
+
tag ${tag}
|
208
|
+
host ${hostname}
|
209
|
+
foo bar
|
210
|
+
</labels>
|
211
|
+
</metric>
|
212
|
+
```
|
213
|
+
|
214
|
+
- `name`: metric name (required)
|
215
|
+
- `type`: metric type (required)
|
216
|
+
- `desc`: description of metric (required)
|
217
|
+
- `key`: key name of record for instrumentation (required)
|
218
|
+
- `<labels>`: additional labels for this metric (optional). See [Labels](#Labels)
|
219
|
+
|
220
|
+
## Labels
|
221
|
+
|
222
|
+
See [Prometheus Data Model](http://prometheus.io/docs/concepts/data_model/) first.
|
223
|
+
|
224
|
+
You can add labels with static value or dynamic value from records. In `prometheus_monitor` input plugin, you can't use label value from records.
|
225
|
+
|
226
|
+
### labels section
|
227
|
+
|
228
|
+
```
|
229
|
+
<labels>
|
230
|
+
key1 value1
|
231
|
+
key2 value2
|
232
|
+
</labels>
|
233
|
+
```
|
234
|
+
|
235
|
+
All labels sections has same format. Each lines have key/value for label.
|
236
|
+
|
237
|
+
You can use placeholder for label values. The placeholders will be expanded from records or reserved values. If you specify `${foo}`, it will be expanded by value of `foo` in record.
|
238
|
+
|
239
|
+
Reserved placeholders are:
|
240
|
+
|
241
|
+
- `${hostname}`: hostname
|
242
|
+
- `${tag}`: tag name
|
243
|
+
|
244
|
+
|
245
|
+
### top-label labels and labels inside metric
|
246
|
+
|
247
|
+
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.
|
248
|
+
|
249
|
+
```
|
250
|
+
<filter message>
|
251
|
+
type prometheus
|
252
|
+
<metric>
|
253
|
+
name message_foo_counter
|
254
|
+
type counter
|
255
|
+
desc The total number of foo in message.
|
256
|
+
key foo
|
257
|
+
<labels>
|
258
|
+
key foo
|
259
|
+
data_type ${type}
|
260
|
+
</labels>
|
261
|
+
</metric>
|
262
|
+
<metric>
|
263
|
+
name message_bar_counter
|
264
|
+
type counter
|
265
|
+
desc The total number of bar in message.
|
266
|
+
key bar
|
267
|
+
<labels>
|
268
|
+
key bar
|
269
|
+
</labels>
|
270
|
+
</metric>
|
271
|
+
<labels>
|
272
|
+
tag ${tag}
|
273
|
+
hostname ${hostname}
|
274
|
+
</labels>
|
275
|
+
</filter>
|
276
|
+
```
|
277
|
+
|
278
|
+
In this case, `message_foo_counter` has `tag`, `hostname`, `key` and `data_type` labels.
|
279
|
+
|
280
|
+
|
281
|
+
## Try plugin with nginx
|
282
|
+
|
283
|
+
Checkout repository and setup.
|
284
|
+
|
285
|
+
```
|
286
|
+
$ git clone git://github.com/kazegusuri/fluent-plugin-prometheus
|
287
|
+
$ cd fluent-plugin-prometheus
|
288
|
+
$ bundle install --path vendor/bundle
|
289
|
+
```
|
290
|
+
|
291
|
+
Download pre-compiled prometheus binary and start it. It listens on 9090.
|
292
|
+
|
293
|
+
```
|
294
|
+
$ wget https://github.com/prometheus/prometheus/releases/download/0.16.1/prometheus-0.16.1.linux-amd64.tar.gz -O - | tar zxf -
|
295
|
+
$ ./prometheus-0.16.1.linux-amd64/prometheus -config.file=./misc/prometheus.yaml -storage.local.path=./prometheus/metrics
|
296
|
+
```
|
297
|
+
|
298
|
+
Install Nginx for sample metrics. It listens on 80 and 9999.
|
299
|
+
|
300
|
+
```
|
301
|
+
$ sudo apt-get install -y nginx
|
302
|
+
$ sudo cp misc/nginx_proxy.conf /etc/nginx/sites-enabled/proxy
|
303
|
+
$ sudo chmod 777 /var/log/nginx && sudo chmod +r /var/log/nginx/*.log
|
304
|
+
$ sudo service nginx restart
|
305
|
+
```
|
306
|
+
|
307
|
+
Start fluentd with sample configuration. It listens on 24231.
|
308
|
+
|
309
|
+
```
|
310
|
+
$ bundle exec fluentd -c misc/fluentd_sample.conf -v
|
311
|
+
```
|
312
|
+
|
313
|
+
Generate some records by accessing nginx.
|
314
|
+
|
315
|
+
```
|
316
|
+
$ curl http://localhost/
|
317
|
+
$ curl http://localhost:9999/
|
318
|
+
```
|
319
|
+
|
320
|
+
Confirm that some metrics are exported via Fluentd.
|
321
|
+
|
322
|
+
```
|
323
|
+
$ curl http://localhost:24231/metrics
|
324
|
+
```
|
325
|
+
|
326
|
+
Then, make a graph on Prometheus UI. http://localhost:9090/
|
327
|
+
|
328
|
+
## Contributing
|
329
|
+
|
330
|
+
1. Fork it ( https://github.com/kazegusuri/fluent-plugin-prometheus/fork )
|
331
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
332
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
333
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
334
|
+
5. Create a new Pull Request
|
335
|
+
|
336
|
+
|
337
|
+
## Copyright
|
338
|
+
|
339
|
+
<table>
|
340
|
+
<tr>
|
341
|
+
<td>Author</td><td>Masahiro Sano <sabottenda@gmail.com></td>
|
342
|
+
</tr>
|
343
|
+
<tr>
|
344
|
+
<td>Copyright</td><td>Copyright (c) 2015- Masahiro Sano</td>
|
345
|
+
</tr>
|
346
|
+
<tr>
|
347
|
+
<td>License</td><td>MIT License</td>
|
348
|
+
</tr>
|
349
|
+
</table>
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = "fluent-plugin-prometheus-thread"
|
3
|
+
spec.version = "0.1.3"
|
4
|
+
spec.authors = ["Masahiro Sano", "James Harlow"]
|
5
|
+
spec.email = ["sabottenda@gmail.com", "j+ruby-gems@thread.com"]
|
6
|
+
spec.summary = %q{A td-agent plugin that collects metrics and exposes for Prometheus.}
|
7
|
+
spec.description = %q{A td-agent plugin that collects metrics and exposes for Prometheus.}
|
8
|
+
spec.homepage = "https://github.com/hythloday/fluent-plugin-prometheus"
|
9
|
+
spec.license = "MIT"
|
10
|
+
|
11
|
+
spec.files = `git ls-files -z`.split("\x0")
|
12
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
13
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
14
|
+
spec.require_paths = ["lib"]
|
15
|
+
|
16
|
+
spec.add_dependency "fluentd"
|
17
|
+
spec.add_dependency "prometheus-client"
|
18
|
+
spec.add_development_dependency "bundler"
|
19
|
+
spec.add_development_dependency "rake"
|
20
|
+
spec.add_development_dependency "rspec"
|
21
|
+
spec.add_development_dependency "test-unit"
|
22
|
+
end
|