Search code examples
grafanainfluxdbgrafana-variable

InfluxDB select aggregate value and tag as string, grouped by tag


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?


Solution

  • 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.