「Promtail」- 日志采集代理

该笔记将记录:与 Promtail 有关的内容、使用方法、以及相关问题的解决办法;

认识

文档:https://grafana.com/docs/loki/latest/send-data/promtail/

Promtail,其为日志采集工具,其将采集分散在各个环境中的日志,并发送到集中的日志存储服务 Grafana Loki 中。

⚠️,注意事项,Promtail is now deprecated and will enter into Long-Term Support (LTS) beginning Feb. 13, 2025. This means that Promtail will no longer receive any new feature updates, but it will receive critical bug fixes and security fixes. … If you are currently using Promtail, you should plan your migration to Alloy. 所以,我们也开始逐步归档 Promtail 相关的笔记,将其整理到该页面中。

概念术语

Configuration

配置文件(promtail.yaml)的配置参数,以及相关说明;

Pipelines

从抓取日志到 发送到日志存储服务,总共分为四步:
1)Parsing stages parse the current log line and extract data out of it. The extracted data is then available for use by other stages.
2)Transform stages transform extracted data from previous stages.
3)Action stages take extracted data from previous stages and do something with them. Actions can:
4)Filtering stages optionally apply a subset of stages or drop entries based on some condition.

Scraping

从日志源(诸如 File、systemd journal、Windows Envent、Syslog 等等)中抓取日志的方法;

Stages

各种 Stages 的使用方法;

Troubleshooting

运行 prometail 命令,能够针对 scrape_configs 配置进行调试,观察其行为

cat my.log | promtail --stdin --dry-run --inspect --client.url http://127.0.0.1:3100/loki/api/v1/push

cat my.log | promtail --config.file promtail.yaml

但是 clients.external_labels 似乎无法通过该方式进行显示,或许是 promtail 2.5.0 暂时不支持;

Cloud setup GCP Logs

官方文档的该部分内容与 GCP 相关,所以并非我们关注的重点,所以我们将忽略该部分;

应用

场景 | 抓取 syslog 内容 | scraping linux-syslog

该笔记将记录:配置 Promtail 抓取 syslog 的方法,以及相关问题的解决办法;

scrape_configs.syslog | Promtail,其提供 syslog 配置,但是其并不能直接抓取 syslog 日志,而是将 Promtail 作为 Listener,然后配置 rsyslog 将日志发送给 Promtail 服务;

但是,我们希望减少对底层操作系统的变更(运维工作),所以并未采用该方案;

scrape_configs.static_configs | 我们直接使用 static_configs 来抓取日志文件:我们的操作系统以 Ubuntu 为主;并且以云原生容器环境来运行;

参考

Troubleshooting | Grafana Loki documentation
Promtail/Scraping | Grafana Loki documentation