简体   繁体   English

Grafana/Loki 可以将字符串转换为 object 并扩展它吗?

[英]Can Grafana/Loki convert a string to object and expand it?

I am parsing Traefik logs into Loki and I have a log entry like:我正在将 Traefik 日志解析到 Loki 中,并且我有一个日志条目,例如:

{
  "Request": "{\"Method\":\"GET\",\"URL\":{\"Scheme\":\"\",\"Opaque\":\"\",\"User\":null,\"Host\":\"\",\"Path\":\"/test\",\"RawPath\":\"\",\"ForceQuery\":false,\"RawQuery\":\"\",\"Fragment\":\"\",\"RawFragment\":\"\"},\"Proto\":\"HTTP/2.0\",\"ProtoMajor\":2,\"ProtoMinor\":0,\"Header\":{\"Accept\":[\"*/*\"],\"User-Agent\":[\"something\"],\"X-Forwarded-Host\":[\"example.com\"],\"X-Forwarded-Port\":[\"443\"],\"X-Forwarded-Proto\":[\"https\"],\"X-Forwarded-Server\":[\"xxx\"],\"X-Real-Ip\":[\"x.x.x.x\"]},\"ContentLength\":0,\"TransferEncoding\":null,\"Host\":\"example.com\",\"Form\":null,\"PostForm\":null,\"MultipartForm\":null,\"Trailer\":null,\"RemoteAddr\":\"x.x.x.x:yyy\",\"RequestURI\":\"/test\",\"TLS\":null}",
  "level": "debug",
  "msg": "vulcand/oxy/roundrobin/rr: begin ServeHttp on request",
  "time": "2021-12-13T11:52:42-05:00"
}

Grafana can detect the objects like level, msg, and request but is there a way to convert that Request line to json and have it detect or expand that as well? Grafana 可以检测级别、消息和请求等对象,但有没有办法将该请求行转换为 json 并让它检测或扩展它? The result should be something like request.method, reqest.URL, etc.结果应该类似于 request.method、reqest.URL 等。

Have you tried using the json operator in your query?您是否尝试在查询中使用json运算符? You can see a demo here if you scroll to min 42: https://grafana.com/go/observabilitycon/2020/keynote-what-is-observability/如果滚动到第 42 分钟,您可以在此处查看演示: https://grafana.com/go/observabilitycon/2020/keynote-what-is-observability/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM