简体   繁体   中英

Average response time by path in loki logs

I have stream of http logs json via Loki that look like:

2022-11-30 16:18:46 {"message":{"duration":"8.37ms","env":"dev","path":"/rest/path1","status":200}} 
2022-11-30 16:18:46 {"message":{"duration":"112.32ms","env":"dev","path":"/rest/path2","status":200}}   
2022-11-30 16:18:46 {"message":{"duration":"32.37ms","env":"dev","path":"/rest/path1","status":200}} 
2022-11-30 16:18:46 {"message":{"duration":"21.337ms","env":"dev","path":"/rest/path3","status":200}}

I'd like to display average response time by path.

I am able convert this data in to table with grafana transformation. and then looking to for average of max duration time based on path.

have you tried looking at range queries? First you would need to extract the duration. See how I did it here using the LogQL Analyzer.

Then you can use a range query with avg_over_time .

You would end up with a query like this:

avg_over_time(
{app="your-app} 
| pattern `<date> <time> <json_content>` 
| line_format "{{.json_content}}" 
| json
| unwrap message_duration | __error__=""[1m]) 
by (message_path)

Hope this helps:).

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.

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