13

I currently have the following config:

<match docker.nginx>
  @type rewrite_tag_filter
  rewriterule1 source stdout docker.nginx.stdout
  rewriterule2 source stderr docker.nginx.stderr
</match>

but this means, that with each container I have to do the same.

This isn't working, but probably you'll get what I want from it:

<match docker.*>
  @type rewrite_tag_filter
  rewriterule1 source stdout docker.*.stdout
  rewriterule2 source stdout docker.*.stderr
</match>

So my question is can I somehow refer to the matched tag in the match block? So if it's nginx/rabbitmq/zookeeper/anything, it will split all event flows into docker.<fluentd-tag>.stdout and stderr.

Thanks in advance!

csaboable
  • 163
  • 8

1 Answers1

1

Looking at Fluentd record_transformer parameter , you could try and use placeholders to refer to captured patterns in the tag, applying dynamic transformations based on those captured values.

For your requirement, you would use a wildcard (*) to capture the tag and then refer to that captured value using a placeholder (${tag_parts[N]}) in the rewrite_tag_filter plugin.

<match docker.*>
  @type rewrite_tag_filter
  rewriterule1 source stdout docker.${tag_parts[1]}.stdout
  rewriterule2 source stderr docker.${tag_parts[1]}.stderr
</match>

In this case, ${tag_parts[1]} would refer to the part of the tag after docker. (e.g., nginx, rabbitmq, zookeeper, etc.).

Any tag that matches the pattern docker.* will have its events rewritten based on the source (either stdout or stderr) to tags like docker.nginx.stdout, docker.rabbitmq.stderr, and so on.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250