Loki status graph from access.log

I don’t think I fully understand Loki’s documentation. Please help me with the following task.

Unfortunately, unwrap expression does’t work with the count_over_time function.

The task is simple:

I want to draw a graph from the access.log file on the lines containing the “GET” message, by status codes, and the “Y” axis shows the number of status codes every 10 minutes (the number of status codes in that unit of time).

The log’s browser:

count_over_time(
  {filename="/var/log/nginx/access.log"} |~ "\"GET\\s"  
  | pattern `<remote_addr> - - [<time_local>] "<request>" <status> <body_bytes_sent> "<http_referer>" "<http_user_agent>" "<http_x_forwarded_for>"`
  | unwrap status [10m]) by (status)
#### parse error : grouping not allowed for count_over_time aggregation

What is the solution?

Thank you!

SOLVED, example for % of 5xx requests:

sum(count_over_time({job="hs-nginx", filename!~".*error.*"} 
  | pattern `<_> - <_> <_> "<_> <_> <_>" <status> <_> <_> "<_>" <_>`
  | status >= 500 
  | __error__=""
  [1m]))/(sum(count_over_time({job="hs-nginx", filename!~".*error.*"} 
  | pattern `<_> - <_> <_> "<_> <_> <_>" <status> <_> <_> "<_>" <_>`
  | __error__=""
  [1m]))/100)
1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.