利用loki分析docker日志
安装loki插件
docker plugin install grafana/loki-docker-driver:latest --alias loki --grant-all-permissions
通过docker-compose管理loki和grafana服务
version: "3"
networks:
loki:
services:
loki:
image: grafana/loki
restart: always
environment:
- TZ=Asia/Shanghai
- LANG=zh_CN.UTF-8
ports:
- 3100:3100
networks:
- loki
grafana:
image: grafana/grafana:latest
restart: always
environment:
- TZ=Asia/Shanghai
- LANG=zh_CN.UTF-8
ports:
- 3000:3000
networks:
- loki
在需要监控的docker服务中增加日志配置
logging:
driver: loki
options:
loki-url: "http://localhost:3100/loki/api/v1/push"
max-size: "50m"
max-file: "10"
loki-pipeline-stages: |
- multiline:
firstline: '^\[\d{2}:\d{2}:\d{2} \w{4}\]'
配置loki数据源
![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/0200bfab1b78452d96c7f1808ce7f021.png)
参考
- https://www.cnblogs.com/turingguo/p/13847003.html