Reputation: 7040
How do I subtract two timeseries in Grafana? Or add two together, divide one by another, etc...? I have found vague hints online about taking differences between timeseries, but nothing that actually tells me how to do so. I'm using Grafana v2.0.2
with Influxdb v0.8
and have played around with the graph controls enough to discover things like the difference
operator I can apply, but I have no idea how to use it. I've attempted to find documentation on this, but the closest I can find is pretty much silent on this topic, and also looks to be slightly out of date, as the interface has changed since those screenshots were taken.
Thanks!
Upvotes: 11
Views: 27895
Reputation: 6629
In recent versions of Grafana, when you edit a panel, you can add two separate queries (+Query
), which will each be assigned a label: A
, B
, etc. Then you can add an expression (+Expression
) and apply a mathematical operation on the other queries, e.g. $A + $B
, $B - $A
, etc.
The arithmetic (+, binary and unary -, *, /, %, exponent **), relational (<, >, ==, !=, >=, <=), and logical (&&, ||, and unary !) operators are supported.
You can choose to show or hide the original queries by clicking on the "eye" icon.
See the documentation for more information.
Upvotes: 1
Reputation: 3901
Another possible solution (that I've only tried with graphite) is to use the sumSeries
and scale
functions. To add two time seriers together, do
sumSeries(first.time.series, second.time.series)
and to get the difference do
sumSeries(first.time.series, scale(second.time.series, -1))
This must be done using the text editor for metrics.
Upvotes: 3
Reputation: 32418
InfluxDB v0.12 support following operations:
Arithmetic operation on aggregation function result:
SELECT 10* MEAN(usage_system) AS avg
FROM cpu WHERE time > now() - 10s;
or arithmetic operation between fields:
SELECT usage_system + usage_user AS avg
FROM cpu WHERE time > now() - 10s;
and most importantly you can perform arithmetic operation between aggregation function results:
SELECT MEAN(usage_system) + MEAN(usage_user) AS avg
FROM cpu
WHERE time > now() - 10s
GROUP BY host;
It's not supported by Grafana GUI editor yet (but you can write it in manual mode).
Upvotes: 6
Reputation: 101
This feature has been added as issue 177 of Grafana:
Setup two series, click the eye icon to hide them and put a third with the division of the preceding ones.
This is only working in Graphite (I'd like it to work on influx badly also)
Upvotes: 7