Promtail - 基于带有 docker-compose 标签的服务发现和 Grafana 日志浏览器中的标签
我正在使用 Grafana 和 Promtail。我有以下设置:
version: "3.3"
networks:
loki:
services:
loki:
image: grafana/loki:k88-c660a7e
ports:
- "3100:3100"
command: -config.file=/etc/loki/local-config.yaml
networks:
- loki
promtail:
image: grafana/promtail:k88-c660a7e
volumes:
- /var/lib/docker/containers:/var/lib/docker/containers
- /var/run/docker.sock:/var/run/docker.sock
- ./promtail-config.yaml:/etc/promtail/promtail-config.yaml
command: -config.file=/etc/promtail/promtail-config.yaml
networks:
- loki
grafana:
image: grafana/grafana:latest
ports:
- "3000:3000"
volumes:
- ./grafana-config.yaml:/etc/grafana/provisioning/datasources/default.yaml
networks:
- loki
mycontainer: # Prints debug output to stdout
build: .
labels:
- "mylabel=true"
networks:
- loki
我想要实现的目标:
- 让 Promtail 忽略除具有
mylabel=true
的容器之外的所有其他容器 - 让 Grafana 在日志资源管理器中显示一个标签,其中容器名称作为标签
我当前的promtail-config.yaml
scrape-configs:
scrape_configs:
- job_name: containers
docker_sd_configs:
- host: unix:///var/run/docker.sock
relabel_configs: # For some reason this drops all logs
- source_labels: [__meta_docker_container_label_mylabel]
regex: "true"
action: keep
static_configs:
- targets:
- localhost
labels:
job: containerlogs
__path__: /var/lib/docker/containers/*/*-json.log
pipeline_stages:
- docker:
如何更改它以实现这一目标?
编辑:这可能会出现 - 对 docker_sd_configs 选项的支持尚未正式发布,但我有 与该项目的贡献者确认该项目可用并且实际上在他们的云中运行。
I am playing with Grafana and Promtail. I have the following setup:
version: "3.3"
networks:
loki:
services:
loki:
image: grafana/loki:k88-c660a7e
ports:
- "3100:3100"
command: -config.file=/etc/loki/local-config.yaml
networks:
- loki
promtail:
image: grafana/promtail:k88-c660a7e
volumes:
- /var/lib/docker/containers:/var/lib/docker/containers
- /var/run/docker.sock:/var/run/docker.sock
- ./promtail-config.yaml:/etc/promtail/promtail-config.yaml
command: -config.file=/etc/promtail/promtail-config.yaml
networks:
- loki
grafana:
image: grafana/grafana:latest
ports:
- "3000:3000"
volumes:
- ./grafana-config.yaml:/etc/grafana/provisioning/datasources/default.yaml
networks:
- loki
mycontainer: # Prints debug output to stdout
build: .
labels:
- "mylabel=true"
networks:
- loki
What I want to achieve:
- Have Promtail ignore all other containers except ones that have the
mylabel=true
- Have Grafana display a label with the container name as label in the log explorer
My current promtail-config.yaml
scrape-configs:
scrape_configs:
- job_name: containers
docker_sd_configs:
- host: unix:///var/run/docker.sock
relabel_configs: # For some reason this drops all logs
- source_labels: [__meta_docker_container_label_mylabel]
regex: "true"
action: keep
static_configs:
- targets:
- localhost
labels:
job: containerlogs
__path__: /var/lib/docker/containers/*/*-json.log
pipeline_stages:
- docker:
How do I change it to achieve that?
EDIT: This is probably going to come up - support for docker_sd_configs
option is not officially released yet, but I have confirmed with a contributor to the project that it is available and in fact running in their cloud.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
filters
进行 Docker 标签选择。使用relabel_configs
根据元值设置附加标签Use
filters
for docker labels selection. Userelabel_configs
for setting additional labels based on meta values