The out_rewrite_tag_filter Output plugin provides a rule-based mechanism for rewriting tags.
How It Works
The plugin is configured by defining a list of rules containing conditional statements and information on how to rewrite the matching tags.
When a message is handled by the plugin, the rules are tested one by one in order. If a matching rule is found, the message tag will be rewritten according to the definition in the rule and the message will be emitted again with the new tag.
Example
Basic Example
This in an example of how to use this plugin to rewrite tags. In the example, records tagged with app.component will have their tag prefixed with the value of the key message:
Nested kubernetes namespace attributes based rules
This is an example of how to use this plugin to rewrite tags with nested attributes which are kubernetes metadata. In the example, records tagged with kubernetes.information will have their tag prefixed with the value of the nested key kubernetes.namespace_name.
Dot notation
Bracket notation
Sample data:
Installation
out_rewrite_tag_filter is included in td-agent by default (v3.0.1 or later). Fluentd gem users will have to install the fluent-plugin-rewrite-tag-filter gem using the following command:
By design, the configuration drops some pattern records first and then it re-emits the next matched record as the new tag name. The example configuration shown below gives an example on how the plugin can be used to define a number of rules that examine values from different keys and sets the tag depending on the regular expression configured in each rule.
The tag value is later used to decide whether the log event shall be dropped or not.
Aggregate + display 404 status pages by URL and referrer to find and
fix dead links.
Send an IRC alert for 5xx status codes on exceeding thresholds.
Aggregate + display 404 status pages by URL and referrer to find and fix dead links.
Collect access log from multiple application servers (config1)
Sum up the 404 error and output to mongoDB (config2)
IMPORTANT
The plugins are required to be installed:
fluent-plugin-rewrite-tag-filter
fluent-plugin-mongo
[Config1] Application Servers
[Config2] Monitoring Server
Send an IRC alert for 5xx status codes on exceeding thresholds.
Collect access log from multiple application servers (config1)
Sum up the 500 error and notify IRC and logging details to mongoDB
(config2)
IMPORTANT
The plugins are required to be installed:
fluent-plugin-rewrite-tag-filter
fluent-plugin-mongo
fluent-plugin-datacounter
fluent-plugin-notifier
fluent-plugin-parser
fluent-plugin-irc
[Config1] Application Servers
[Config2] Monitoring Server
FAQ
With rewrite-tag-filter, logs are not forwarded. Why?
If you have the following configuration, it doesn't work:
In this case, rewrite_tag_filter causes an infinite loop because the fluentd's routing is executed from top-to-bottom. So, you need to change the tag like this: