I am sending json logs to loki and visualizing in grafana. Initially, my logs looked like as following.
{
"log": "{\"additionalDetails\":{\"body\":{},\"ip\":\"::ffff:1.1.1.1\",\"params\":{},\"query\":{},\"responseTime\":0,\"userAgent\":\"ELB-HealthChecker/2.0\"},\"context\":\"http\",\"endpoint\":\"/healthz\",\"level\":\"info\",\"message\":\"[::ffff:1.1.1.1] HTTP/1.1 GET 200 /healthz 0ms\",\"requestId\":\"9fde4910-86cd-11ec-a1c5-cd8277a61e4a\",\"statusCode\":200}\n",
"stream": "stdout",
"time": "2022-02-05T21:49:58.178290044Z"
}
To make it more usabe, I am using following query.
{app="awesome-loki-logs-with-grafana"} | json | line_format "{{.log}}"
And the results are really good. It automaticaly detects fileds as following.
How can I filter by statusCode, which is already being detected by grafana?
您可以创建一个具有 200、401、403、404 等值的“状态”自定义变量,并在 LogQL 中使用该变量,如下例所示:
{app="awesome-loki-logs-with-grafana"} | json | statusCode==$status
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.