问题
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!
回答1:
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)
回答2:
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).
回答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.
来源:https://stackoverflow.com/questions/30010364/multi-timeseries-operations-in-grafana