Filter out specific containers during ingesting

Using promtail, I’m collecting all logs from /var/lib/docker/containers//.log, but I would like to filter out some during ingesting.

I’m currently trying to do this by getting ‘tag’ from the docker logging (json-file), and using a matcher section to filter out anything which does not have a ‘tag’ set, however this does not seem to be working. Is Matcher evaluated before json perhaps? Is there another way to achieve what I want to do?

    static_configs:
      - targets:
        - localhost
        labels:
          job: docker

          # Start promtail with -config.expand-env
          host: ${HOSTNAME}

          # /var/lib/docker/containers:/logs/containers:ro
          __path__: /logs/containers/*/*.log

    pipeline_stages:
      - docker: {}

      - json:
          expressions:
            # Get tag from logging (json-file)
            tag: attrs.tag

      - match:
          # Drop everything that does not have a tag!
          selector: '{tag!=""}'

      - multiline:
        # WARN  2022-01-25 ...
        # DEBUG 2022-01-25 ...
          firstline: '^[A-Z]+\s+\d+-\d+-\d+'
          max_wait_time: 3s
      - regex:
          expression: '(?P<level>^[A-Z]+)\s+.*$'
      - labels:
          tag:
          level:

    relabel_configs:
      - source_labels: [host]
        regex: "(.*)"
        target_label: __host__

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.