How to use fluentd+elasticsearch+grafana to display the first 12 characters of the container ID? How to use fluentd+elasticsearch+grafana to display the first 12 characters of the container ID? kubernetes kubernetes

How to use fluentd+elasticsearch+grafana to display the first 12 characters of the container ID?


Try something like this at the end of containers.input.conf:

<filter kubernetes.**>  @type record_transformer  enable_ruby  <record>    docker.container_id ${record["docker.container_id"][0,12]}  </record></filter>


If it is okay to only store 12-character IDs, you can add a fluent filter parser (tested with Fluent Bit only):

parsers.conf

[PARSER]   Name    dockerid_parser   Format  regex   Regex   ^(?<container_id>.{12})

fluent-docker.conf

[SERVICE]    ...    Parsers_File /full/path/to/parsers.conf...[FILTER]    Name         parser    Match        *    Key_Name     container_id    Parser       dockerid_parser    Reserve_Data On...