Skip to content

Commit 49e7de7

Browse files
added additional custom labels support for the metrics
1 parent e6233a5 commit 49e7de7

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ $ gem install fluent-plugin-throttle
2323
group_bucket_period_s 60
2424
group_bucket_limit 6000
2525
group_reset_rate_s 100
26+
<labels>
27+
key1 value1
28+
key2 value2
29+
<labels>
2630
</filter>
2731
```
2832

@@ -137,6 +141,31 @@ When a group reaches its limit, metrics will be emitted for the logs being dropp
137141
Metrics for the filter is
138142
- `fluentd_throttle_rate_limit_exceeded`
139143

144+
## Labels
145+
146+
See [Prometheus Data Model](http://prometheus.io/docs/concepts/data_model/) first.
147+
148+
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.
149+
150+
### labels section
151+
152+
```
153+
<labels>
154+
key1 value1
155+
key2 value2
156+
</labels>
157+
```
158+
159+
All labels sections has same format. Each lines have key/value for label.
160+
161+
You can use placeholder for label values. The placeholders will be expanded from reserved values and records.
162+
If you specify `${hostname}`, it will be expanded by value of a hostname where fluentd runs.
163+
164+
Reserved placeholders are:
165+
166+
- `${hostname}`: hostname
167+
- `${worker_id}`: fluent worker id
168+
140169
## License
141170

142171
Apache License, Version 2.0

lib/fluent/plugin/filter_throttle.rb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
module Fluent::Plugin
66
class ThrottleFilter < Filter
77
Fluent::Plugin.register_filter('throttle', self)
8+
include Fluent::Plugin::PrometheusLabelParser
89
include Fluent::Plugin::Prometheus
910

1011
desc "Used to group logs. Groups are rate limited independently"
@@ -61,7 +62,7 @@ def configure(conf)
6162

6263
@group_key_paths = group_key.map { |key| key.split(".") }
6364
@group_key_symbols = (group_key.map {|str| str.gsub(/[^a-zA-Z0-9_]/,'_')}).map(&:to_sym)
64-
65+
6566
raise "group_bucket_period_s must be > 0" \
6667
unless @group_bucket_period_s > 0
6768

@@ -83,7 +84,17 @@ def configure(conf)
8384
raise "group_warning_delay_s must be >= 1" \
8485
unless @group_warning_delay_s >= 1
8586

86-
@base_labels = {}
87+
hostname = Socket.gethostname
88+
expander_builder = Fluent::Plugin::Prometheus.placeholder_expander(log)
89+
expander = expander_builder.build({ 'hostname' => hostname, 'worker_id' => fluentd_worker_id })
90+
@base_labels = parse_labels_elements(conf)
91+
@base_labels.each do |key, value|
92+
unless value.is_a?(String)
93+
raise Fluent::ConfigError, "record accessor syntax is not available in metric labels for throttle plugin"
94+
end
95+
@base_labels[key] = expander.expand(value)
96+
end
97+
8798
end
8899

89100
def start

0 commit comments

Comments
 (0)