0

I am using an InfluxDB data source in Grafana. I have a repeating panel of graphs, grouped by a tag value. I am wishing to sort these graphs by an aggregate numeric value, rather than the tag value itself. A trivial InfluxDB query would be:

SELECT sum(value) FROM "application__request-count" GROUP BY method
value method
123 first
234 second

This would be fine, however Grafana variables only appear to work with a single field. I am therefore looking to concatenate the aggregate value and the tag then split them apart in Grafana itself. Something closer to:

value
123|first
234|second

I naively tried:

SELECT sum(value) + "|" + method FROM "application__request-count" GROUP BY method

However I receive the InfluxDB error: "binary expressions cannot mix aggregates and raw fields"

Is there a way to do what I'm looking for in Influx?

nullPainter
  • 2,676
  • 3
  • 22
  • 42
  • Do you need to have Grafana dashboard variable with all `method` tag values? – Jan Garaj Mar 02 '22 at 00:16
  • That's correct. Perhaps what I want can't be done, because I want to sort it as well. The use case is that I have a SingleStat per API endpoint. The SingleStat has the endpoint name as the title, and a count of hits as the value. What I'm after is to list these in order of the hit count, descending. Currently the charts are listed alphabetically, because that's what the Grafana variable is. – nullPainter Mar 02 '22 at 00:30
  • Have you tried a different separation character, other than `|`? – Matt Mar 02 '22 at 06:25

1 Answers1

0

1.) Problem 1: Grafana works with nontime series in the dashboard variable definition. Unfortunately, any InfluxQL query SELECT ... FROM measurement ... generates time series.

2.) Problem 2: InfluxQL doesn't support concatenation. So any concatenations know from the SQL (e.g. |) doesn't work in the InfluxQL. InfluxQL is not a SQL.

Unfortunately, your request can't be implemented in the Grafana. If you hack some problem, then you will have another problems.

It is better to modify requirement and have more suitable panel for that. I would say one query, which return data aggregated per API and then use table panel - you can sort table by clicking on the table header value.

Jan Garaj
  • 25,598
  • 3
  • 38
  • 59
  • Thanks Jan. The requirements are purely visual, and my dashboard works remarkably well from that perspective. It appears that this can be done using Prometheus, but Prometheus != InfluxDB. – nullPainter Mar 02 '22 at 19:28