Skip to content

Commit 2f92f95

Browse files
committed
add "Plugin Helper: Metrics" page and API specification change
Signed-off-by: Shizuo Fujita <[email protected]>
1 parent a9e71f7 commit 2f92f95

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

.gitbook.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ redirects:
204204
v1.0/articles/api-plugin-helper-storage: developer/api-plugin-helper-storage.md
205205
v1.0/articles/api-plugin-helper-socket: developer/api-plugin-helper-socket.md
206206
v1.0/articles/api-plugin-helper-http_server: developer/api-plugin-helper-http_server.md
207+
v1.0/articles/api-plugin-helper-metrics: developer/api-plugin-helper-metrics.md
207208

208209
# Obsolete Pages
209210
v1.0/categories/data-analytics: README.md

SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@
190190
* [Plugin Helper: Event Loop](plugin-helper-overview/api-plugin-helper-event_loop.md)
191191
* [Plugin Helper: Extract](plugin-helper-overview/api-plugin-helper-extract.md)
192192
* [Plugin Helper: Formatter](plugin-helper-overview/api-plugin-helper-formatter.md)
193+
* [Plugin Helper: Metrics](plugin-helper-overview/api-plugin-helper-metrics.md)
193194
* [Plugin Helper: Inject](plugin-helper-overview/api-plugin-helper-inject.md)
194195
* [Plugin Helper: Parser](plugin-helper-overview/api-plugin-helper-parser.md)
195196
* [Plugin Helper: Record Accessor](plugin-helper-overview/api-plugin-helper-record_accessor.md)

plugin-helper-overview/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ It will include `Timer`, `Storage`. and `CompatParameters` plugin helpers.
2323
* [`extract`](api-plugin-helper-extract.md)
2424
* [`formatter`](api-plugin-helper-formatter.md)
2525
* [`inject`](api-plugin-helper-inject.md)
26+
* [`metrics`](api-plugin-helper-metrics.md)
2627
* [`parser`](api-plugin-helper-parser.md)
2728
* [`record_accessor`](api-plugin-helper-record_accessor.md)
2829
* [`server`](api-plugin-helper-server.md)
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Plugin Helper: Metrics
2+
3+
The `metrics` plugin helper manages the metrics values in plugins.
4+
5+
Here is an example:
6+
7+
```ruby
8+
require 'fluent/plugin/input'
9+
10+
module Fluent::Plugin
11+
class ExampleInput < Input
12+
Fluent::Plugin.register_input('example', self)
13+
14+
# 1. Load metrics helper
15+
helpers :metrics
16+
17+
def configure(conf)
18+
super
19+
20+
# 2. Create parser plugin instance
21+
@metrics = metrics_create(namespace: "fluentd", subsystem: "input", name: "example", help_text: "Example metrics")
22+
end
23+
24+
def start
25+
super
26+
27+
# 3. Increase metrics value
28+
@metrics.inc
29+
30+
end
31+
32+
def statistics
33+
stats = super
34+
35+
# 4. Retrieve metrics value
36+
stats = {
37+
'input' => stats["input"].merge({ 'example' => @metrics.get })
38+
}
39+
stats
40+
end
41+
end
42+
```
43+
44+
For more details, see the following articles:
45+
46+
* [Metrics Plugins Overview](../metrics/)
47+
48+
## Methods
49+
50+
### `metrics_create(namespace: "fluentd", subsystem: "metrics", name:, help_text:, labels: {}, prefer_gauge: false)`
51+
52+
This method creates a metrics instance.
53+
54+
* `namespace`: The namespace for the metrics.
55+
* `subsystem`: The names that represent specific functions or components.
56+
* `name`: The metrics name.
57+
* `help_text`: The description for metrics.
58+
* `labels`: The key/value pair for metrics labels.
59+
* `prefer_gauge`: Use gauge instead of counter for the metrics if `true`.
60+
61+
Since 1.19.0, `metrics_create` method generates a getter method with the specified `name` on the calling instance.
62+
63+
## Plugins using `metrics`
64+
65+
* [`buffer`](../buffer/)
66+
* [`filter`](../filter/)
67+
* [`input`](../input/)
68+
* [`output`](../output/)
69+
70+
If this article is incorrect or outdated, or omits critical information, please [let us know](https://github.com/fluent/fluentd-docs-gitbook/issues?state=open). [Fluentd](http://www.fluentd.org/) is an open-source project under [Cloud Native Computing Foundation \(CNCF\)](https://cncf.io/). All components are available under the Apache 2 License.
71+

0 commit comments

Comments
 (0)