fluent-plugin-prometheus 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 975f71bc42e2fcbd393003e0de70226c450c3ecc
4
+ data.tar.gz: 98548ff7299d46702d17a39e204bd05e610dcf67
5
+ SHA512:
6
+ metadata.gz: f95fae92733fc3af07cd27fec952af31772d55dee91ae3eded8bb234c7b0b76272cc667e97ca8ada41fbea4dfaf12c73d12bba209ce63028c31ab74adfac2cd3
7
+ data.tar.gz: 91a012c917969ac1278ba5769302ade6fde3113a364f79c013e5ce29488d488aa38be73acd77fe1e28f753fecb81f30e98584bb38512944bbe56895ba3c174ee
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /Gemfile.fluentd.0.10.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+ *.bundle
12
+ *.so
13
+ *.o
14
+ *.a
15
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.1
5
+ - 2.2
6
+
7
+ gemfile:
8
+ - Gemfile
9
+ - Gemfile.fluentd.0.10
10
+
11
+ script:
12
+ - bundle exec rake spec
13
+
14
+ sudo: false
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-prometheus.gemspec
4
+ gemspec
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org/'
2
+ gem 'fluentd', '~> 0.10.0'
3
+ gem 'fluent-plugin-record-reformer'
4
+ gemspec
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,350 @@
1
+ # fluent-plugin-prometheus, a plugin for [Fluentd](http://fluentd.org)
2
+
3
+ [![Build Status](https://travis-ci.org/kazegusuri/fluent-plugin-prometheus.svg?branch=master)](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, 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 respotiroy and setup it.
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
+ $ mkdir prometheus
295
+ $ wget https://github.com/prometheus/prometheus/releases/download/0.13.3/prometheus-0.13.3.linux-amd64.tar.gz -O - | tar zxf - -C prometheus
296
+ $ ./prometheus/prometheus -config.file=./misc/prometheus.conf -storage.local.path=./prometheus/metrics
297
+ ```
298
+
299
+ Install Nginx for sample metrics. It listens on 80 and 9999.
300
+
301
+ ```
302
+ $ sudo apt-get install -y nginx
303
+ $ sudo cp misc/nginx_proxy.conf /etc/nginx/sites-enabled/proxy
304
+ $ sudo chmod 777 /var/log/nginx && sudo chmod +r /var/log/nginx/access.log
305
+ $ sudo service nginx restart
306
+ ```
307
+
308
+ Start fluentd with sample configuration. It listens on 24231.
309
+
310
+ ```
311
+ $ bundle exec fluentd -c misc/fluentd_sample.conf -v
312
+ ```
313
+
314
+ Generate some records by accessing nginx.
315
+
316
+ ```
317
+ $ curl http://localhost/
318
+ $ curl http://localhost:9999/
319
+ ```
320
+
321
+ Confirm that some metrics are exported via Fluentd.
322
+
323
+ ```
324
+ $ curl http://localhost:24231/metrics
325
+ ```
326
+
327
+ Then, make a graph on Prometheus UI. http://localhost:9090/
328
+
329
+ ## Contributing
330
+
331
+ 1. Fork it ( https://github.com/kazegusuri/fluent-plugin-prometheus/fork )
332
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
333
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
334
+ 4. Push to the branch (`git push origin my-new-feature`)
335
+ 5. Create a new Pull Request
336
+
337
+
338
+ ## Copyright
339
+
340
+ <table>
341
+ <tr>
342
+ <td>Author</td><td>Masahiro Sano <sabottenda@gmail.com></td>
343
+ </tr>
344
+ <tr>
345
+ <td>Copyright</td><td>Copyright (c) 2015- Masahiro Sano</td>
346
+ </tr>
347
+ <tr>
348
+ <td>License</td><td>MIT License</td>
349
+ </tr>
350
+ </table>
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
@@ -0,0 +1,22 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "fluent-plugin-prometheus"
3
+ spec.version = "0.1.0"
4
+ spec.authors = ["Masahiro Sano"]
5
+ spec.email = ["sabottenda@gmail.com"]
6
+ spec.summary = %q{A fluent plugin that collects metrics and exposes for Prometheus.}
7
+ spec.description = %q{A fluent plugin that collects metrics and exposes for Prometheus.}
8
+ spec.homepage = "https://github.com/kazegusuri/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