[英]Combining multiple log lines from Loki in Grafana
I have stream of http logs (fastify pino format) via Loki that look like:我通过 Loki 有 http 日志(fastify pino 格式)的 stream 看起来像:
[2022-07-25T16:59:40.796Z] INFO: incoming request {"req":{"method":"GET","url":"/api/v1/teams/6vYE9rpOPl/members","hostname":"forge.flowforge.loc","remoteAddress":"10.1.106.162","remotePort":38422},"reqId":"req-t6"}
[2022-07-25T16:59:40.810Z] INFO: request completed {"res":{"statusCode":200},"responseTime":13.292339086532593,"reqId":"req-t6"}
I'd like to display average response time by path, but I'm struggling to work out how to combine the 2 log lines correlated by the reqId
to get the url
and responseTime
together.我想按路径显示平均响应时间,但我正在努力研究如何组合由
reqId
相关的 2 条日志行以将url
和responseTime
结合在一起。
I can extract and parse the json for the 2 lines separately but not together.我可以分别提取和解析两行的 json 但不能一起解析。
I don't think it's doable with Loki alone.我认为仅靠 Loki 是行不通的。 For that you would need either:
为此,您需要:
One solution I can think of is using Grafana transformations :我能想到的一种解决方案是使用Grafana 转换:
line
field becomes a valid JSON.line
字段变为有效的 JSON。 Do not parse the JSON in LogQL: the extracted fields wouldn't be recognized by the Grafana transformations later on.Grafana transformations are pretty powerful but a bit non-intuitive too, so the solution would require some experimenting. Grafana 转换非常强大,但也有点不直观,因此解决方案需要一些试验。 The debug transformation functionality might be helpful.
调试转换功能可能会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.