feat(monitoring): 接入 Loki + Promtail 日志采集,Grafana 可直接搜索容器日志

This commit is contained in:
Zhou Weidong authored and trae-solo-agent committed 2026-10-28 10:38:41 +08:00
1 parent 5d139783c9
commit fc9e429187
4 files changed
+135

No files matched your search

+34
View File
@@ -0,0 +1,34 @@
# Author: fruit.com.cn
# Promtail:通过 Docker 服务发现自动采集所有容器的 stdout/stderr 日志,推送到 Loki。
server:
http_listen_port: 9080
grpc_listen_port: 0
positions:
filename: /tmp/positions.yaml
clients:
- url: http://loki:3100/loki/api/v1/push
batchwait: 1s
batchsize: 1048576
scrape_configs:
- job_name: docker-containers
docker_sd_configs:
- host: unix:///var/run/docker.sock
refresh_interval: 5s
relabel_configs:
# 容器名(去掉开头的 /)
- source_labels: ['__meta_docker_container_name']
regex: '/(.*)'
target_label: container
# 日志流:stdout / stderr
- source_labels: ['__meta_docker_container_log_stream']
target_label: stream
# 容器 ID 前 12 位
- source_labels: ['__meta_docker_container_id']
target_label: container_id
regex: '(.{12}).*'
# 镜像名
- source_labels: ['__meta_docker_container_image']
target_label: image