Add label with regexp from container name in promtail

80 views Asked by At

I have a some of docker containers with names:

project1-api
project1-crons
project2-api
project2-crons
etc…

And I need to have a label like “project1”, “project2” to filter in in Grafana Loki So I think to parse log in promtail with some regexp to add label “project1”, “project2” etc, but cann’t to have a correct config of Promtail Maybe there are other way to solve my problem, so you are welcome…

Try to config pipeline_stage for docker job but without success My config work for now is:

pipeline_stages:
- json:
    expressions:
      level: level
relabel_configs:
  - source_labels: ['__meta_docker_container_name']
    regex: '/(.*)'
    target_label: 'container'

And I need to have a label like “project1”, “project2” to filter in in Grafana Loki

1

There are 1 answers

0
yungkei On
- job_name: docker_scrape 
  docker_sd_configs:
      # Address of the Docker daemon.    Use unix:///var/run/docker.sock for a local setup.
      - host: <string>
        refresh_interval: 5s
  relabel_configs:
      - source_labels: ['__meta_docker_container_name']
        regex: '/(.*)'
        target_label: 'container'

Note that the discovery will not pick up finished containers. That means Promtail will not scrape the remaining logs from finished containers after a restart.