Arithmetic operation with regex select clause?



I am trying to display with grafana 2 different retention policies on the same dashboard. (one retention policies contains long term data downsampled)

It is working well on this kind of query :
select mean(/(mean_)?idle$/) from "$RP".""

depending on the retention policy RP, it displays either “idle” or “mean_idle”

But if I want to display the cpu “not idle” I can’t …
select 100 - mean(/(mean_)?idle$/) from "$RP".""
This query returns me no data points for any retention policies … :pensive:

Is there a limitation on influxdb side that forbid me of doing this ?
Should I open an issue on github ?

Best Regards,

1 Like

@hurtauda This sounds like a grafana issue. I would suggest opening an issue on Grafana.


I am trying to do the same and I think the issue is on the influx side as it seems you cannot perform math on a SELECT that contains regex.

Any workaround?

1 Like

I have same problem.

In my case I have 2 retention policies:

  • raw_data (data falls into this RP every 30 sec);
  • downsampled_data_5m (data from RP raw_data aggregates into this RP every 5 minutes).

At Grafana dashboard I have variable $retention_policy, that equals to raw_data and downsampled_data_5m.

My ordinary queries look like this:
SELECT /^usage_system$|^mean_usage_system$/ FROM "$retention_policy"."cpu" WHERE ("host" =~ /$server$/ and "cpu" = 'cpu-total')

So I have ability to switch value of variable $retention_policy and show data from different RP.

But sometimes there is a need to perform arithmetic operations with result of queries. For example, there is no metric in Telegraf that shows usage of inodes in percent:
show field keys from disk
name: disk
fieldKey fieldType
-------- ---------
free integer
inodes_free integer
inodes_total integer
inodes_used integer
total integer
used integer
used_percent float

To calculate free inodes in percent I need to perform query like this:
SELECT "inodes_used" / "inodes_total" * 100 FROM "disk"

For case described above I need to add regexp into query like this:
SELECT (/^inodes_used$|mean_inodes_used$/ / /^inodes_total$|^mean_inodes_total$/ * 100) FROM "disk"

But regular expressions doesn’t work in queries with mathematic operations. Is it possible to add support of them?