1

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

enter image description here

instead I would something like

enter image description here

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

enter image description here

and this is the table output

enter image description here

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.

0

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

I've tried but still not getting the desired output. I've updated the question with details.
@sparkle cast status as text in that query, becaue you have it as numeric type now, e.g. status::text AS "metric",. You should to also mention used Grafana version and panel type first in your question.
I'm still experiencing the same issue as well, using Grafana 10 though.
2

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: enter image description here

Source

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.