10

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!

Tombart
  • 30,520
  • 16
  • 123
  • 136
staticfloat
  • 6,752
  • 4
  • 37
  • 51
  • With Graphite this is easy. Not sure how to do it with InfluxDB. The place to ask is in the InfluxDB mailing list or on their irc channel on freenode – Torkel May 04 '15 at 07:02
  • Could you explain how to do it with Graphite? That would be useful as I might be able to map the concepts on my own, and I would at least know what form the question should be in, if not the answer. – staticfloat May 04 '15 at 13:46

4 Answers4

7

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.

grafana - graphite queries

This is only working in Graphite (I'd like it to work on influx badly also)

Tombart
  • 30,520
  • 16
  • 123
  • 136
XFMoulet
  • 101
  • 1
  • 5
  • Excellent, thank you for the screenshot! Can you elucidate a little bit on why there is a difference between influxdb and graphite? Are the series operations happening inside of the database engine? That seems strange to me, as I'd assume things would scale much nicer if the clients did the data manipulation, but then again I didn't write grafana. :P – staticfloat May 07 '15 at 14:30
  • well, I didn't design grafana so I cannot tell you why .. maybe because queries are directly sent to tghe DB layer ? – XFMoulet May 11 '15 at 07:15
6

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

Tombart
  • 30,520
  • 16
  • 123
  • 136
3

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.

Johannes Hoff
  • 3,731
  • 5
  • 31
  • 37
0

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.

enter image description here

DV82XL
  • 5,350
  • 5
  • 30
  • 59