Why GAUGE of int values is a float?

Post general support questions here that do not specifically fall into the Linux or Windows categories.

Moderators: Developers, Moderators

User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Re: Why GAUGE of int values is a float?

Post by gandalf »

He did some nice CDEF which prints an integer number, yes.
But in case you followed my link, or, perhaps better http://www.vandenbogaerdt.nl, you will see that rrdtool in almost any case performs "normalization to 300 sec boundaries since epoch" when updating the rrd file. You won't get back the "correct" number by any means of post-processing.
That is due to the fact, that rrdtool stores "rates" internally (values per second). It does so to get rid of "wrong math" in case polling interval varies by a second or two (again, see links for more hints).

This will produce "funny results" e.g. in case you want to monitor UP/DOWN status, represented by e.g. "0" and "1". The interval, that shows a change from "0" to "1" will produce a fractional number, meaning: "This interval was the one where the value changed" (As you won't know, at which "exact" point in time within that interval the "real" change occured). So it's not really "funny" but sort of "problem of interpreting values 'correctly'".

Well, that's how rrdtool does it. Knowing this should help in many cases. Rounding to a whole integer may get "as close as possible". Else, it may happen that rrdtool is not the best tool for dealing with your specific use case.

In case your problem lies with understanding the mentioned CDEF, please ask again
R.
User avatar
schurzi
Posts: 42
Joined: Sat Oct 11, 2008 8:45 am
Location: Germany
Contact:

Re: Why GAUGE of int values is a float?

Post by schurzi »

@smlick:
I have attached a screenshot of the CDEF. Hope that helps.

@gandalf:
I am aware, that these numbers are already smoothed by rrdtool and in normal cases this is not a problem it is even desired !).

My case for using this approach was as following:
We are monitoring how many users are logged in to a system. While 45671,8 users can be explained, if you look at a average value, it can be hard to explain the same amount as a maximum or current value.

So I came up with this CDEF.
Attachments
cacti_cdef.JPG
cacti_cdef.JPG (98.07 KiB) Viewed 2214 times
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it." - Brian W. Kernighan
User avatar
smlick
Cacti User
Posts: 267
Joined: Tue May 20, 2008 4:09 am
Location: Italy, Rome

Re: Why GAUGE of int values is a float?

Post by smlick »

Tnx 4 share.
I'll try it.

Regards
Alessio
Cacti Version 0.8.8c production / 0.8.8c test W2008 -- Plugin:Weathermap - Monitor - CAMM 1.6.7 :) - Nectar - GPS Map
User avatar
smlick
Cacti User
Posts: 267
Joined: Tue May 20, 2008 4:09 am
Location: Italy, Rome

Re: Why GAUGE of int values is a float?

Post by smlick »

Sorry but in CDEF item type --> Special Data Source, CDEF item value I didn't see "CURRENT_DATA_SOURCE", there's only current data source item maximum or minimum value.
Any idea?

Cacti ver. 0.8.7g

Regards
Alessio
Attachments
CDEF.JPG
CDEF.JPG (63.47 KiB) Viewed 2213 times
Cacti Version 0.8.8c production / 0.8.8c test W2008 -- Plugin:Weathermap - Monitor - CAMM 1.6.7 :) - Nectar - GPS Map
User avatar
schurzi
Posts: 42
Joined: Sat Oct 11, 2008 8:45 am
Location: Germany
Contact:

Re: Why GAUGE of int values is a float?

Post by schurzi »

CURRENT_DATA_SOURCE = Current Graph Item data Source :)
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it." - Brian W. Kernighan
User avatar
smlick
Cacti User
Posts: 267
Joined: Tue May 20, 2008 4:09 am
Location: Italy, Rome

Re: Why GAUGE of int values is a float?

Post by smlick »

:oops:

Regards
Alessio
Cacti Version 0.8.8c production / 0.8.8c test W2008 -- Plugin:Weathermap - Monitor - CAMM 1.6.7 :) - Nectar - GPS Map
kryztoval
Posts: 2
Joined: Tue Jan 22, 2013 11:06 am

Re: Why GAUGE of int values is a float?

Post by kryztoval »

What on earth prevented you from rounding using:

CURRENT_DATA_SOURCE,0.5,+,FLOOR

Wouldn't that just be simpler?
User avatar
schurzi
Posts: 42
Joined: Sat Oct 11, 2008 8:45 am
Location: Germany
Contact:

Re: Why GAUGE of int values is a float?

Post by schurzi »

well, my first thougt when reading this, is "what ... on ... earth ... prevented ... me ... !" oO

But I think your soultion would not be correct for -1.5. Mathematical correct would be -2 , your solution would calculate -1.
While this is an edge case, your solutions is propably better to understand and much easier to implement. And negative values are not often a problem with RRDs.

EDIT:
While looking at this, I realized that my original solution is wrong for +1.5. -.-

A correct solution seems to be:
CURRENT_DATA_SOURCE,CURRENT_DATA_SOURCE,ABS,+,CURRENT_DATA_SOURCE,0.5,-,CEIL,CURRENT_DATA_SOURCE,0.5,+,FLOOR,IF

eg:
use +0.5 and FLOOR if value is positive
use -0.5 and CEIL if value is negative
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it." - Brian W. Kernighan
kryztoval
Posts: 2
Joined: Tue Jan 22, 2013 11:06 am

Re: Why GAUGE of int values is a float?

Post by kryztoval »

I am not a fan of "IFs"

Current_data_source,abs,0.5,+,FLOOR,Current_data_source,current_data_source,abs,/,*

This should work for negative numbers also.

edit:
I don't use cacti, so I wouldn't know if you can enter this, but this is shorter:
Current_data_source,abs,0.5,+,FLOOR,Current_data_source,dup,abs,/,*

And just clarifying what that does if anyone cares:
Get the absolute value and add 0.5, floor that, store.
Divide current value against the absolute of itself (this will effectively return 1 or -1 just like SIGN would)
Multiply both results.

This will works as long as you want -1.5 and 1.5 to be rounded to -2 and 2 respectively.
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Re: Why GAUGE of int values is a float?

Post by gandalf »

schurzi wrote:@smlick:
I have attached a screenshot of the CDEF. Hope that helps.

@gandalf:
I am aware, that these numbers are already smoothed by rrdtool and in normal cases this is not a problem it is even desired !).

My case for using this approach was as following:
We are monitoring how many users are logged in to a system. While 45671,8 users can be explained, if you look at a average value, it can be hard to explain the same amount as a maximum or current value.

So I came up with this CDEF.
This CDEF does some rounding on the value. But, depending on numbers used during consolidation, the "deviation" from what you expect may exceed 1. Thus, rounding will NOT always return what you desired
R.
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests