我有以下日志,它是嵌套的JSON
{"level":30,"time":1627625600625,"pid":15676,"hostname":"admin-hp-elitebook-840-g2","reqId":"req-2","req":{"method":"POST","url":"/v1/login","hostname":"127.0.0.1:3000","remoteAddress":"127.0.0.1","remotePort":55884},"msg":"incoming request"}
然后,我想为method、URL、host创建标签。我尝试了在promtail中使用如下JSON表达式。我尝试解析JSON,但我可以提取请求,但我不知道如何解析promtail中嵌套JSON
scrape_configs: - job_name: plainlog pipeline_stages: - json: expressions: req: req - labels: - output: source: req static_configs: - targets: - localhost labels: job: plainlog __path__: /home/nidhin/Desktop/plainlog/*log
发布于 2021-09-02 05:02:30
您需要添加另一个json stage。对于每一层嵌套的json,您再添加一个阶段,以便从上一层提取的数据中解析数据。例如:
- json: