Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Single-stat percentage change from initial value in graphite/grafana?

Tags:

Is there a way to simply show the change of a value over the selected time period? All I'm interested in is the offset of the last value compared to the initial one. The values can vary above and below these over the time period, it's not really relevant (and would be exceptions in my case).

For an initial value of 100 and an final value of 105, I'd expect a single stat box displaying 5%.

I have the feeling I'm missing something obvious obvious, but can't find a method to display this deceptively simple task.

Edit:

I'm trying to create a scripted Grafana dashboard that will automatically populate disk consumption growth for all our various volumes. The data is already in Graphite, but for purposes of capacity management and finance planning (which projects/departments gets billed) it would be helpful for managers to have a simple and coarse overview of which volumes grow outside expected parameters.

The idea was to create a list of single-stat values with color coding that could easily be scrolled through to find abnormalities. Disk usage would obviously never be negative, but volatility in usage between the start and end of the time period would be lost in this view. That's not a big concern for us as this is all shared storage and such usage is expected to a certain degree.

The perfect solution would be to have the calculations change dynamically based on the selected time period.

I'm thinking that this is not really possible (at least not easily) to do with just Graphite and Grafana and have started looking for alternative methods. We might have to implement a different reporting system for this purpose.

Edit 2

I've tried implementing the suggested solution from Leonid, and it works after a fashion. The calculations seems somewhat off from what I expected though.

My test dashboard looks like follows:

Storage Growth over 30 days

If I were to calculate the change manually, I'd end up with roughly 24% change between the start (7,23) and end (8.96) value. Graphite calculates this to 19%. It's probably a reason for the discrepancy, probably something to do with it being a time-series and not discreet values?

As a sidenote: The example is only 30 days, even though the most interesting number would be a year. We don't have quite a year of data in Graphite yet and having a 30 day view is also interesting. It seems I have to implement several dashboards with static times.

like image 1000
Dacite Avatar asked Mar 27 '16 09:03

Dacite


People also ask

How is percentage calculated in Grafana?

Yes, it is possible to format result as percentage in the singlestat panel: Choose to edit the panel. Go to Visualization tab/section. In Unit input, choose percent(0-1.0)


1 Answers

You certainly can do that for some fixed period. For example following query take absolute difference betweent current metric value and value that metric has one minute ago (i.e. initial value) and then calculate it's percentage of inital value.

asPercent(absolute(diffSeries(my_metric, timeShift(my_metric, '1m'))), timeShift(my_metric, '1m'))

I believe you can't do that for time period selected in Grafana picker.

But is that really what you need? It's seems strange because as you said value can change in both directions. Maybe standard deviation would be more suitable for you? It's available in Graphite as stdev function.

like image 75
Leonid Vasilev Avatar answered Oct 12 '22 10:10

Leonid Vasilev