fluentd create tag based on key value

♀尐吖头ヾ 提交于 2019-12-24 18:42:45

问题


Shipping logs from Kubernetes to Fluentd aggregator.

Is there a way to transform one of the key values into the tag value? For example there is key value for application_name. If this could be transformed into the tag value it would be possible to direct to different outputs.

Thanks,


回答1:


There is no way to edit the tag once the record is created.

The way to do this is to re-emit the record with the rewrite tag filter

You could do something like this:

<match kubernetes_logs>
  @type rewrite_tag_filter
  <rule>
    key application_name
    pattern (.+)
    tag $1
  </rule>
</match>

That said, this method makes fluentd to proccess twice as much records. If you only need to direct records to different endpoints, usually output plugins allow to filter records by key.




回答2:


There is a fluentd record_transformer plugin. https://docs.fluentd.org/v1.0/articles/filter_record_transformer

<filter foo.bar>
  @type record_transformer
  <record>
    hostname "#{Socket.gethostname}"
    tag ${tag}
  </record>
</filter>

Example input: {"message":"hello world!"}

Example output : {"message":"hello world!", "hostname":"db001.internal.example.com", "tag":"foo.bar"}



来源:https://stackoverflow.com/questions/50806299/fluentd-create-tag-based-on-key-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!