Fluentd 输出过滤插件,用于重写匹配指定属性的标签。
Rewrite Tag Filter for Fluentd. It is designed to rewrite tags like mod_rewrite.
Re-emit the record with rewritten tag when a value matches/unmatches with a regular expression.
Also you can change a tag from Apache log by domain, status code (ex. 500 error),
user-agent, request-uri, regex-backreference and so on with regular expression.
This is an output plugin because fluentd's filter doesn't allow tag rewrite.
| fluent-plugin-rewrite-tag-filter | Fluentd | Ruby |
|---|---|---|
| >= 2.0.0 | >= v0.14.2 | >= 2.1 |
| = v0.12.0 | >= 1.9 |
Install with gem or td-agent-gem command as:
# for system installed fluentd
$ gem install fluent-plugin-rewrite-tag-filter
# for td-agent2 (with fluentd v0.12)
$ sudo td-agent-gem install fluent-plugin-rewrite-tag-filter -v 1.6.0
# for td-agent3 (with fluentd v0.14)
$ sudo td-agent-gem install fluent-plugin-rewrite-tag-filterFor more details, see Plugin Management
hostnamebatch or record. batch will emit events per rewritten tag, and decrease IO. record will emit events per record.batch/regexp/ is preferred because /regexp/ style can support character classes such as /[a-z]/.
The pattern without slashes will cause errors if you use patterns start with character classes.falseIt's a sample to exclude some static file log before split tag by domain.
…$ mongo
MongoDB shell version: 2.2.0
> use apache_access
switched to db apache_access
> show collections
ExampleMaps
ExampleNews
ExampleMail
unmatchedOn starting td-agent, Logging supported like below.
…Each rule is evaluated against record[key], and a record that matches none of the rules is not re-emitted, so it is silently dropped. A missing field is read as an empty string, and a normal rule (invert false) is skipped before its pattern is evaluated when the value is empty. Because of this, neither pattern /.+/ nor pattern /.*/ fires for a record that lacks the field, and a plain catch-all rule only covers records where the field exists and is not empty.
To catch every record regardless of whether the field exists, use an inverted rule whose pattern can never match anything, and place it as the last rule:
key domain
pattern /(?!)/
invert true
tag site.unmatched
(?!) is an empty negative lookahead, so it never matches any input, and combined with invert true the rule always fires whether the field holds a value, is empty, or is absent from the record.
Note that this also means an inverted rule behaves differently from what you might expect for a missing field in general. For example, pattern /^200$/ with invert true fires for a record that has no status field at all, because an empty string does not match that pattern.
If you want to keep unmatched records instead of discarding them, note that re-emitting them with the same tag into the same route is not possible. This is an output plugin, so the surrounding has already routed the event here, and emitting it again with the same tag would make the same catch it again forever. The plugin therefore skips an event whose tag is unchanged unless a label is given. To keep unmatched records, either rewrite them to a tag that the same `` does not cover, or keep the tag and set label on the catch-all rule so that they are routed to another label:
key domain
pattern /(?!)/
invert true
tag ${tag}
label @UNMATCHED
The `` section must consume these records (for example, write them out). If it re-emits them with the tag unchanged and routes them back to @UNMATCHED, they loop for the same reason.
Alternatively, put record_modifier or record_transformer in front of this plugin so that the field always exists with a default value.
Dot notation:
@type rewrite_tag_filter
key $.kubernetes.namespace_name
pattern ^(.+)$
tag $1.${tag}
Bracket notation:
@type rewrite_tag_filter
key $['kubernetes']['namespace_name']
pattern ^(.+)$
tag $1.${tag}
These example configurations can process nested attributes like following:
{
"kubernetes": {
"namespace_name": "default"
}
}When original tag is kubernetes.var.log, this will be converted to default.kubernetes.var.log.
It is supported these placeholder for new_tag (rewritten tag).
${tag}__TAG__${tag_parts[n]}__TAG_PARTS[n]__${hostname}__HOSTNAME__The placeholder of ${tag_parts[n]} and __TAG_PARTS[n]__ acts accessing the index which split the tag with "." (dot).
For example with td.apache.access tag, it will get td by ${tag_parts[0]} and apache by ${tag_parts[1]}.
Note Currently, range expression ${tag_parts[0..2]} is not supported.
remove_tag_prefixThis option adds removing tag prefix for ${tag} or __TAG__ in placeholder.
remove_tag_regexpThis option adds removing tag regexp for ${tag} or __TAG__ in placeholder.
hostname_commandBy default, execute command as hostname to get full hostname.
On your needs, it could override hostname command using hostname_command option.
It comes short hostname with hostname_command hostname -s configuration specified.
It's a sample to rewrite a tag with placeholder.
…In addition to changing tags, you can also change event's route by setting the label for the re-emitted event.
For example, given this configuration:
@type rewrite_tag_filter
key domain
pattern ^www\.example\.com$
tag web.${tag}
key domain
pattern ^(.*)\.example\.com$
tag other.$1
label other
message: {"domain": "www.example.com"} will get its tag changed to
web.apache.access, while message
{"domain": "api.example.com"} will get its tag changed to other.api and
be sent to label other
Example1: how to analyze response_time, response_code and user_agent for each virtual domain websites.
https://github.com/y-ken/fluent-plugin-rewrite-tag-filter/blob/master/example.conf
Example2: how to exclude specified patterns before analyze response_time for each virtual domain websites.
https://github.com/y-ken/fluent-plugin-rewrite-tag-filter/blob/master/example2.conf
http://d.hatena.ne.jp/yoshi-ken/20120701/1341137269
http://www.slideshare.net/baguzy/fluentd-meetup-2-14073930
https://gist.github.com/matsumana/4078096
http://dayafterneet.blogspot.jp/2012/12/fluentdflowcounter-plugin.html
http://y-ken.hatenablog.com/entry/fluent-plugin-rewrite-tag-filter-v1.2.0
http://y-ken.hatenablog.com/entry/fluent-plugin-rewrite-tag-filter-v1.2.1
http://y-ken.hatenablog.com/entry/fluent-plugin-rewrite-tag-filter-v1.3.0
http://y-ken.hatenablog.com/entry/fluent-plugin-rewrite-tag-filter-v1.3.1
http://chopl.in/blog/2013/06/07/postgresql_csv_log_with_fluentd.html
http://techblog.raccoon.ne.jp/archives/35031163.html
http://y-ken.hatenablog.com/entry/fluent-plugin-rewrite-tag-filter-v1.4.1
Pull requests are very welcome!!
Copyright : Copyright (c) 2012- Kentaro Yoshida (@yoshi_ken)
License : Apache License, Version 2.0
暂无开放 Issues,或尚未同步最近议题。