'Create bar chart for average value of a field by label?

I have Promtail set up on my servers to label log lines by host, endpoint, etc. and Loki to extract response times from these log lines as a field.

Here's a sample log from the explorer in Grafana: Screenshot of a log line from the explorer in Grafana, expanded to show labels (endpoint, endpoint_type, filename, host, promtail_config_version, and request_type) and detected fields (action_time_ms, ts, and tsNs)

What I want to do is turn these logs into a bar chart, showing average response time (action_time_ms) by endpoint.

I've found the metric queries page in the Loki LogQL docs, but I'm not sure how to turn that into the right kind of query for Grafana to make a bar chart out of it. Do fields even matter?

Grafana v8.4.2, Loki/Promtail v2.4.2.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source