Hello!
Please have a look at the attached graph. It shows the total and used sizes of a SAPDB (MaxDB) database. In order to also show the rate of change (how fast does the database grow/shrink), I'm polling the used space parameter twice - once as a GAUGE, once as a DERIVE.
However, the |sum| function does not seem to work correctly with negative values. As you can see, the total sum (which should show the total growth of the database from the first to the last value) is larger that the difference between the minimum and maximum value of the used space. This should not be possible. When selecting a timeframe for the graph where the database size went smaller, the total sum still shows a positive value (although the average growth is a negative value).
Basically, what I want to graph / calculate is the number of bytes the database has grown / shrunken from the first to the last datapoint in the graph (regardless how big or small it was in between).
I hope, somebody can help me.
Florian
Sum not working correctly
Moderators: Developers, Moderators
Sum not working correctly
- Attachments
-
- dbgrowth.jpg (61.66 KiB) Viewed 3295 times
Re: Sum not working correctly
I've found a solution myself. The problem is, that the rrd fetch function of rrd cannot read negative values.
I've patched rrd.php in order to be able to sum up negative values:
354c371
< $regexps[$i] .= '([0-9]{1}\.[0-9]+)e([\+-][0-9]{2,3})';
---
> $regexps[$i] .= '([\-]{0,1}[0-9]{1}\.[0-9]+)e([\+-][0-9]{2,3})';
356c373
< $regexps[$i] .= '[0-9]{1}\.[0-9]+e[\+-][0-9]{2,3}';
---
> $regexps[$i] .= '[\-]{0,1}[0-9]{1}\.[0-9]+e[\+-][0-9]{2,3}';
Maybe its worth thinking about putting this into the main cacti code.
Since I was summing up non-bandwidth data, I also has to deal with the fact that Cacti uses 1000 instead of 1024 as the base for the sum.
Patches to rrd.php:
735c762
< if (preg_match_all("/\|sum:(\d|auto):(current|total):(\d):(\d+|auto)\|/", $graph_variables[$field_name][$graph_item_id], $matches, PREG_SET_ORDER)) {
---
> if (preg_match_all("/\|sum:(\d|auto|kauto):(current|total|atomic):(\d):(\d+|auto)\|/", $graph_variables[$field_name][$graph_item_id], $matches, PREG_SET_ORDER)) {
Patches to graph_variables.php:
261a262,277
> }elseif ($regexp_match_array[1] == "kauto") {
> if (abs($summation) < 1024) {
> $summation_label = "bytes";
> }elseif (abs($summation) < 1048576) {
> $summation_label = "KB";
> $summation /= 1024;
> }elseif (abs($summation) < 1073741824) {
> $summation_label = "MB";
> $summation /= 1048576;
> }elseif (abs($summation) < 1099511627776) {
> $summation_label = "GB";
> $summation /= 1073741824;
> }else{
> $summation_label = "TB";
> $summation /= 1099511627776;
> }
This seems to work at least for me...
I've patched rrd.php in order to be able to sum up negative values:
354c371
< $regexps[$i] .= '([0-9]{1}\.[0-9]+)e([\+-][0-9]{2,3})';
---
> $regexps[$i] .= '([\-]{0,1}[0-9]{1}\.[0-9]+)e([\+-][0-9]{2,3})';
356c373
< $regexps[$i] .= '[0-9]{1}\.[0-9]+e[\+-][0-9]{2,3}';
---
> $regexps[$i] .= '[\-]{0,1}[0-9]{1}\.[0-9]+e[\+-][0-9]{2,3}';
Maybe its worth thinking about putting this into the main cacti code.
Since I was summing up non-bandwidth data, I also has to deal with the fact that Cacti uses 1000 instead of 1024 as the base for the sum.
Patches to rrd.php:
735c762
< if (preg_match_all("/\|sum:(\d|auto):(current|total):(\d):(\d+|auto)\|/", $graph_variables[$field_name][$graph_item_id], $matches, PREG_SET_ORDER)) {
---
> if (preg_match_all("/\|sum:(\d|auto|kauto):(current|total|atomic):(\d):(\d+|auto)\|/", $graph_variables[$field_name][$graph_item_id], $matches, PREG_SET_ORDER)) {
Patches to graph_variables.php:
261a262,277
> }elseif ($regexp_match_array[1] == "kauto") {
> if (abs($summation) < 1024) {
> $summation_label = "bytes";
> }elseif (abs($summation) < 1048576) {
> $summation_label = "KB";
> $summation /= 1024;
> }elseif (abs($summation) < 1073741824) {
> $summation_label = "MB";
> $summation /= 1048576;
> }elseif (abs($summation) < 1099511627776) {
> $summation_label = "GB";
> $summation /= 1073741824;
> }else{
> $summation_label = "TB";
> $summation /= 1099511627776;
> }
This seems to work at least for me...
The fact that Cacti's rrdfetch function is unable to process negative numbers is definitely a bug. As a result, I created an official patch which will be included in the next release of Cacti. Please see the patches page for details (I like being able to say that now ).
As for the 1024 base value, I am not exactly sure what I am going to do about this yet. As you can imagine, the summation function was developed with traffic in mind.
-Ian
As for the 1024 base value, I am not exactly sure what I am going to do about this yet. As you can imagine, the summation function was developed with traffic in mind.
-Ian
Who is online
Users browsing this forum: No registered users and 12 guests