Singlestat Math - Square Root

I’d like to compute the square root of a value using the Singlestat Math plugin (Singlestat Math plugin for Grafana | Grafana Labs) but it’s either not working or I’m using incorrect syntax.

I have tried

  • sqrt(x)
  • math.sqrt(x)
  • x**(0.5)
  • x^(0.5)

What is your datasource? If Influx, are you using InfluxQL or Flux?

Thanks for the reply Grant,

Our data source is InfluxQL

Can you paste the whole text of your query, e.g.

SELECT moving_average(mean(“FurnaceA”), 10) FROM “stations” WHERE $timeFilter GROUP BY time(1m) fill(null)

The query to get the base variable “X” itself is really simple:

SELECT “Meas_x” / 25.4 FROM “autogen”./^$Cell$/ WHERE $timeFilter
"FORMAT AS Time series ALIAS BY X

Then i’ve done an additional query thru the Singlestat Math plugin, but i can’t seem to find a command that will give me the square root.

It doesn’t look like a clever decision - single stat math panel calculates in your browser (so you may overload your browser/local machine easily, if you have a lot of data and complex calculation).

Why you don’t use InfluxQL SQRT function, e.g.:

SELECT SQRT("Meas_x" / 25.4) 
FROM "autogen"./^$Cell$/ 
WHERE $timeFilter

InfluxDB server is very likely a better place to execute calculation.

1 Like

Thanks for the input @jangaraj

The problem with that solution is that I am attempting to do the root of a sum of squares across two channels and influxDB does not support multi-channel arithmetic.

It may be the case that I just have to do this in Kapacitor, but singleStat Math seemed promising for the small load f calculations required for this dashboard.

I think Flux can do the query you are attempting, but you may want to verify first with a Flux expert on the Influx forum.

Problem is:

That is there to “replace variables with zero from math field when there is no alias by field to replace them”, but it replaces also “sqrt”, so “sqrt(x)” is evaluated as “0(x)”. You can fork the plugin and fix it somehow in your own fork (I wouldn’t expect that author will fix it any soon).