Reputation: 7398
I want to display a multi-line chart where each line it's the value of a column. For example, "status" has several values: 200, 404, 500 etc.. and I want to see a line for each. On X-axis I have to see how many records had the status=200 and so on..
I've tried with this
SELECT
created_at AS "time",
status,
count(*)
FROM api_logs
group BY time, status
but it's showing
instead I would something like
UPDATED: I tried with this query
SELECT
$__timeGroupAlias(created_at, '5m'),
status AS "metric",
count(*) AS "count"
FROM api_logs
WHERE $__timeFilter(created_at)
GROUP BY 1,2
ORDER BY 1
but I got this chart
and this is the table output
I would see a line for each status. Where Y is the count of event for that status. Basically If I see a spike for a line (errors 500) I have to worry.
Upvotes: 1
Views: 2089
Reputation: 527
The above answer did not solve it for me.
I'm using Grafana 10 and what solved is was using the multi-frame time series transformation:
Upvotes: 1
Reputation: 28714
SQL query with 5min time aggregation with PostgreSQL macros for Grafana 8.2:
SELECT
$__timeGroupAlias(created_at, '5m'),
status AS "metric",
count(*) AS "count"
FROM api_logs
WHERE $__timeFilter(created_at)
GROUP BY 1,2
ORDER BY 1
created_at
column is timestamptz
type.
Upvotes: 3