Grafana difference between two datapoints

20.7k Views Asked by At

In a Grafana dashboard with several datapoints, how can I get the difference between the last value and the previouse one for the same metric? Perhaps the tricky part is that the time between 2 datapoints for the same metric is not know.

so the desired result is the <metric>.$current_value - <metric>.$previouse_value for each point in the metricstring.

Edit: The metrics are stored in graphite/Carbon DB.

thanks

1

There are 1 best solutions below

0
On BEST ANSWER

You need to use the derivative function

This is the opposite of the integral function. This is useful for taking a running total metric and calculating the delta between subsequent data points.

This function does not normalize for periods of time, as a true derivative would. Instead see the perSecond() function to calculate a rate of change over time.

Together with the keepLastValue

Takes one metric or a wildcard seriesList, and optionally a limit to the number of ‘None’ values to skip over.

Continues the line with the last received value when gaps (‘None’ values) appear in your data, rather than breaking your line.

Like this

derivative(keepLastValue(your_mteric))

A good example can be found here http://www.perehospital.cat/blog/graphite-getting-derivative-to-work-with-empty-data-points