Grafana difference between two datapoints

Lou_Ds picture Lou_Ds · Nov 23, 2018 · Viewed 11.2k times · Source

In a Graphana 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 tiem between 2 datapoins 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

Answer

Gal S picture Gal S · Nov 27, 2018

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