https://github.com/kentaro/fluent-plugin-rewrite#fluent-plugin-rewrite
Component组成
type rewrite
remove_prefix apache.log
add_prefix filtered
<rule>
key path
pattern \\?.+$
replace
</rule>
<rule>
key path
pattern (/[^/]+)\\?([^=]+)=(\\d)
replace \\1/\\2/\\3
</rule>
<rule>
key status
pattern ^500$
ignore true
</rule>
<rule>
key path
pattern ^\/(users|entries)
append_to_tag true
fallback others
</rule>
<rule>
key is_loggged_in
pattern 1
append_to_tag true
tag user
</rule>
</match>
Configuration
Output plugin to rewrite messages' tags/values along with pattern matching and re-emit them.
输出插件改写消息:tag/values 以及模式匹配并且回送他们。
Synopsis概要
remove_prefix / add_prefix (@******重点)
remove_prefix apache.log
add_prefix filtered
- remove_prefix: removes the string from a prefix of tag.
- add_prefix: prepend the string to a tag.
-
删除前缀:删除一个tag前缀的字符串。(什么意思:删除一个tag的前缀,tag的前缀是什么,删除它。就是 tag 要匹配度的 在source 中 tag lj.test 这个文件,)增加前缀:预先考虑到标签的字符串。(什么意思)
type rewrite rewrite 重写插件,猜测(要重写,你必须是要把原先要匹配的东西tag删了,然后在forward之前,从新写入一个新文件,这就是下面的两行代码的实现) remove_prefix apache.log add_prefix filtered
rule: replace (@******重点)
For example, if you want to filter out query string form URL string:
<rule>
key path
pattern \\?.+$
replace
</rule>
It executes pattern matching against a value related with key
and replaces it with empty string if it matches.
它执行对相关key值的模式匹配和如果它匹配用空字符串代替。(说明:如果它匹配。是说,如果它和key值匹配,就用空字符串来代替。replace翻译成:代替。空字符串是什么意思:就是replace后面决定是要用什么来代替)
/foo?bar=baz -> /foo
This time, if you want to rewrite path string along with some pattern:
这一次,如果你想修改路径字符串和一些模式。
<rule>
key path
pattern (/[^/]+)\\?([^=]+)=(\\d)
replace \\1/\\2/\\3
</rule>
It executes pattern matching against a value related with key
and replaces it with replace
if it matches.
/foo?bar=1 -> /foo/bar/1
rule: ignore
For example, if you want to skip a message which matches some pattern:
例如:如果你想跳过匹配一些模式的一个消息。
<rule>
key status
pattern ^500$
ignore true
</rule>
It executes pattern matching against a value related with key
and skip emitting the message if it matches.
它执行对相关key值得模式匹配和如果它匹配跳过发射。(跳过发射:就是ignore)
rule: append_to_tag
<rule>
key path
pattern ^\/(users|entries)
append_to_tag true
</rule>
It executes pattern matching against a value related with key
and append mathed strings to message tag. For example:
它执行对相关key值得模式匹配和把matched (匹配)的字符串附加到消息标签。
apache.log { "path" : "/users/antipop" }
the messabe above will be re-emmited as the message below:
上面的消息将会重新按照下面的消息发送:
apache.log.users { "path" : "/users/antipop" } (说明:为什么
append_to_tag true 增加后的显示是在apache.log后会加上user)
If you set fallback
option like below:
如果你按下面的后备选项设置:
<rule>
key path
pattern ^\/(users|entries)
append_to_tag true
fallback others
</rule>
the value of fallback
option will be appended to message tag.
fallback
选项的值将会增加到消息日志中。
apache.log { "path" : "/foo/bar" }
This time, the messabe above will be re-emmited as the message below:
上面的消息将会重新按照下面的消息发送:(加入fallbach others 后在apache.log后也会加入一个后缀)
apache.log.others { "path" : "/foo/bar" }
If tag
option set,(如果设置tag选项)
<rule>
key is_loggged_in
pattern 1
append_to_tag true
tag user
</rule>
the value designated by tag
will be appended to the original tag, that is:
这个被指定的tag值将会被附加到原始的tag,即:
test { "is_logged_in" => "1" }
will be
test.user { "is_logged_in" => "1" } (看到这里前面的疑惑才豁然开朗了,是这么来的)
rule: last
If you set last
option to true, rewriting chain stops applying rule where the pattern matches first.
如果你把last选项设置为true,在第一次模式匹配重写链停止应用规则。(不知所云)
<rule>
key path
pattern ^/foo$
replace /bar
last true
</rule>
<rule>
key path
pattern ^/bar$
replace /baz
</rule>
This rules will be applied like below:
这个规则将应用如下:
{ "path" => "/foo" }(这说的是什么:key path 然后path指向 pattern,这个在上面没注意到)
will be replaced with
{ "path" => "/bar" }
and the chain stops here. Therefore, the second rule is never applied. 下面的两句也是来说明这个的。
{ "path" => "/bar" }
will be replaced by the second rule as usual.
{ "path" => "/baz" }
和链停止在这里。因此,第二个规则是从来没有用的。(明白了:第二个规则指:"path" => "/foo" 这个规则是被"path" => "/baz"取代了)
Installation
Add this line to your application's Gemfile:
gem 'fluent-plugin-rewrite'
And then execute:
$ bundle
Or install it yourself as:
$ gem install fluent-plugin-rewrite
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request