Hi!
I have only used Grafana (with Loki) for a few days, so this is probably obvious, sorry in that case. I’m making my very first query but I keep getting stuck.
TLDR:
The aggregation functions in LogQL does not function like I expect since it does not aggregate the number of rows. I get the same number of rows with some sort of rolling aggregation value for the interval applied to each row.
What is the best way to aggregate rows on time intervals in Grafana using either LogQL or transforms?
Longer:
In SQL I would write something like this to aggregate data by the hour:
SELECT COUNT(foo), SUM(bar) ... GROUP BY date_format(datecolumn, '%Y%m%d%H' )
But in Grafana my code seems needlessly complex.
First I made this query:
{job="nginx"}
|= ``
| json
| line_format "request_uri='{{.request_uri}}', time='{{.time_iso8601 | toDate \"2006-01-02T15:04:05Z07:00\" | date \"2006-01-02 15\"}}:00:00', megabytes_sent='{{divf .bytes_sent 1048576}}'"
Then I use the transform “Group by” on time and calculate a count on request_uri and a sum on megabytes_sent.
Is there a better way?