我使用rsyslog从大约5000台服务器收集日志。我的收集器使用RFC5424格式将所有日志写入NFS卷上的单个文件。我正在将这个NFS卷挂载在我的promtail节点上,并使用static_config来刮取文件。我可以在洛基查看日志。
我的问题是:我在日志条目中没有看到任何标签。我无法执行基于主机名的LogQL查询或基于工具的任何类型的查询。
这是我的活动内容的相关部分:
scrape_configs:
- job_name: system
static_configs:
- targets:
- localhost
labels:
job: varlogs
__path__: /data/rsyslog.log有没有方法将标签应用于static_config?
发布于 2023-04-04 03:46:03
是的,您可以使用static_config实现这一点,您需要使用Promtail的管道阶段来解析日志并提取创建标签所需的信息。
以下是您修改的版本:
scrape_configs:
- job_name: system
pipeline_stages:
# Assuming the logs are in RFC5424 format, use the regex to extract the hostname and facility
- regex:
expression: '.*?<(\d+)>(\d+)\s\d+-\d+-\d+T\d+:\d+:\d+.\d+\S+\s+(\S+)\s+.*'
output:
source_labels: [facility, hostname]
# Map the extracted facility number to a facility name
- labels:
facility:
replacement: "${1}"
- labels:
hostname:
replacement: "${2}"
static_configs:
- targets:
- localhost
labels:
job: varlogs
__path__: /data/rsyslog.log您需要调整regex以匹配日志的特定格式。
https://serverfault.com/questions/1127834
复制相似问题