2

Grafana noob with simple query results formatted as table:

SELECT "locales" FROM "postgresql" WHERE ("environment" = 'stage') AND $timeFilter

Time locales
2022-03-17 15:31:00 en
2022-03-17 15:31:01 en-us
2022-03-17 15:32:00 en
2022-03-17 15:32:01 en-us
2022-03-17 15:33:00 en-us
2022-03-17 15:34:00 en-us

I'd like to count occurrences and group by locales, like:

locale count
en 2
en-us 4

I tried the following:

  • Using a transform, I can group by locales, but this does not give me count.
  • Adding a transform to count returns a single value of total rows, not individual locale counts.
  • Including count and group-by in the query: SELECT "locales", count("locales") FROM "postgresql" WHERE ("environment" = 'stage') GROUP BY "locales". This gives InfluxDB Error: mixing aggregate and non-aggregate queries is not supported.

I know Grafana is more time-based, but this should be easily doable, no? Thanks in advance for any tips!

Jan Garaj
  • 25,598
  • 3
  • 38
  • 59
calipoop
  • 792
  • 9
  • 31
  • How postresql can return Influxdb error? Edit your question and tags - it is not clear what are you using. – Jan Garaj Mar 18 '22 at 21:43
  • We're using telegraf for `postgresql_extensible` queries on our postgres database. I believe it's Grafana that's returning the Influxdb error? – calipoop Mar 18 '22 at 22:08

1 Answers1

0

count by(locales) ( yourmetrics)

  • Remember that Stack Overflow isn't just intended to solve the immediate problem, but also to help future readers find solutions to similar problems, which requires understanding the underlying code. This is especially important for members of our community who are beginners, and not familiar with the syntax. Given that, **can you [edit] your answer to include an explanation of what you're doing** and why you believe it is the best approach? – Jeremy Caney Mar 08 '23 at 00:09