[HOWTO] Summations other than bandwidth

If you figure out how to do something interesting/cool in Cacti and want to share it with the community, please post your experience here.

Moderators: Developers, Moderators

Post Reply
gauret
Posts: 3
Joined: Fri Jan 20, 2006 6:54 am

[HOWTO] Summations other than bandwidth

Post by gauret »

I've searched this forum for previous submissions, and it seems that many people would like to use the bandwidth_summation function for adding values other than bytes.

This function is used by adding a comment like "Total Out: |sum:auto:current:2:auto|" in a graph. It does sum the datasource values in the timeframe, but assumes the unit is bytes and adds "B" to the result.

I needed to display the number of mails going through a server (incoming and outgoing separately) so I lightly tweaked the cacti source code to remove the "B" unit.

Here's what you need to do :

- In lib/rrd.php, copy the paragraph starting with /* bandwidth summation */ and change the call to the variable_bandwidth_summation function to variable_generic_summation. Change the regexp to match on "gsum" instead of "sum" :

Code: Select all

--- rrd.php.orig        2007-01-28 17:38:21.000000000 +0100
+++ rrd.php     2007-01-28 17:38:52.000000000 +0100
@@ -886,6 +886,13 @@
                                                $graph_variables[$field_name][$graph_item_id] = str_replace($match[0], variable_bandwidth_summation($match, $graph_item, $graph_items, $graph_start, $graph_end, $rra["steps"], $ds_step), $graph_variables[$field_name][$graph_item_id]);
                                        }
                                }
+
+                               /* generic summation */
+                               if (preg_match_all("/\|gsum:(\d|auto):(current|total|atomic):(\d):(\d+|auto)\|/", $graph_variables[$field_name][$graph_item_id], $matches, PREG_SET_ORDER)) {
+                                       foreach ($matches as $match) {
+                                               $graph_variables[$field_name][$graph_item_id] = str_replace($match[0], variable_generic_summation($match, $graph_item, $graph_items, $graph_start, $graph_end, $rra["steps"], $ds_step), $graph_variables[$field_name][$graph_item_id]);
+                                       }
+                               }
                        }

                        /* if we are not displaying a legend there is no point in us even processing the auto padding,
Next, we'll copy the variable_bandwidth_summation function into variable_generic_summation and remove the "B" units. This function is defined in lib/graph_variables.php. Just copy-n-paste the variable_bandwidth_summation function, and remove the "B" in the elseif at the end, when $summation_label is set (the diff is very large, so I don't copy it here)

Now, in you graph templates, just add a comment for your selected datasource, with the following value :

Code: Select all

Total: |gsum:auto:current:2:auto|
That should do it !
Cyberwizzard
Posts: 13
Joined: Tue Sep 04, 2007 7:01 am

Post by Cyberwizzard »

Thanks for the howto :)

I modified the gsum function to divide the summation by 300: like other people I have absolute readouts which span 5 minutes (not readouts per second like the summation assumes).

So for everyone else who has this issue and simply wants to sum the values in the RRD instead of upgrading the values on a per second interval, simply follow the guide above and above the summation label block insert the following:

Code: Select all

// Fix the multiplication issue
$summation /= 300;
And you are set :)
colchaodemola
Posts: 17
Joined: Sun Feb 18, 2007 11:09 am

Post by colchaodemola »

Hi guys , great tool. But , is there a way to apply a CDEF function to the result ?
I would like to multuply for 0.049 in some graphics and for 2.37 in others , and leave untouched in others :)
User avatar
rony
Developer/Forum Admin
Posts: 6022
Joined: Mon Nov 17, 2003 6:35 pm
Location: Michigan, USA
Contact:

Post by rony »

CDEF can not be applied because this value is calculated outside of RRDTool.
[size=117][i][b]Tony Roman[/b][/i][/size]
[size=84][i]Experience is what causes a person to make new mistakes instead of old ones.[/i][/size]
[size=84][i]There are only 3 way to complete a project: Good, Fast or Cheap, pick two.[/i][/size]
[size=84][i]With age comes wisdom, what you choose to do with it determines whether or not you are wise.[/i][/size]
ceyounger
Posts: 44
Joined: Fri Feb 10, 2006 2:59 pm
Location: Orange County, CA
Contact:

Post by ceyounger »

Cyberwizzard wrote:Thanks for the howto :)

I modified the gsum function to divide the summation by 300: like other people I have absolute readouts which span 5 minutes (not readouts per second like the summation assumes).

So for everyone else who has this issue and simply wants to sum the values in the RRD instead of upgrading the values on a per second interval, simply follow the guide above and above the summation label block insert the following:

Code: Select all

// Fix the multiplication issue
$summation /= 300;
And you are set :)
Weird, I didn't have to this that last part--it was skewing my numbers. I basically read a counter and use gsum for totals. I'm also running a 1 min poller.

Anyway, this post is a great find! Solved a problem I've had for a while!
X505
Posts: 39
Joined: Fri Jun 29, 2007 3:53 pm
Contact:

Post by X505 »

Thanks guys for this useful trick !

edit : i'd like to share what this great mod let me do (spoolers stats):

Image

Image
duanew
Posts: 16
Joined: Tue Apr 03, 2007 12:04 am
Location: Brisbane, Australia

Very good post

Post by duanew »

I found this very useful.

I followed most of the instructions but I found I had to use:

Code: Select all

Total: |gsum:0:atomic:0:auto|
I fiddled a bit with the Data Template Step and the "$summation /=6;".

I created the RRD manually with a step size of 1800. I think atomic was added so that the $summation no longer needs to be adjusted.
caboom
Posts: 8
Joined: Mon Jul 05, 2010 1:54 pm

Post by caboom »

thanks gauret for the gsum and cyberwizzard for the /= 300 :p
i really needed that.. ;)
now i can have the total sum for my mail stats!
Chrysalis
Cacti User
Posts: 70
Joined: Fri Sep 19, 2008 10:14 am
Location: UK

Re: [HOWTO] Summations other than bandwidth

Post by Chrysalis »

guys can someone either attach an edited graph_variables.php or do a code box for it please, is incredibly confusing and I now have no rrd's been created.

Am baffled as to why this isnt a built in function on cacti as well.
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Re: [HOWTO] Summations other than bandwidth

Post by gandalf »

Feature requests outside the related forum and code contributions outside the mantis system won't get tracked properly. That's the main reason. E.g. now I'm not sitting at my development system, so I can't put the code in asap.
Personally, I _love_ code contributions, as this is the fastest way to get new features supported.
R.
jxkoepk
Posts: 3
Joined: Fri Dec 03, 2010 2:27 pm

Re: [HOWTO] Summations other than bandwidth

Post by jxkoepk »

I could use a little help with this.. Sorry if this is a stupid question...

in the graph_variables.php do I just totally remove the code below, or comment it out?

Code: Select all

 if (preg_match("/\d+/", $regexp_match_array[1])) {
                $summation /= pow(10,intval($regexp_match_array[1]));
        }elseif ($regexp_match_array[1] == "auto") {
                if ($summation < 1000) {
                        $summation_label = "bytes";
                }elseif ($summation < 1000000) {
                        $summation_label = "KB";
                        $summation /= 1000;
                }elseif ($summation < 1000000000) {
                        $summation_label = "MB";
                        $summation /= 1000000;
                }elseif ($summation < 1000000000000) {
                        $summation_label = "GB";
                        $summation /= 1000000000;
                }else{
                        $summation_label = "TB";
                        $summation /= 1000000000000;
                }
        }
and there is a line:

Code: Select all

 $summation = 0;
do I change the line to $summation /=300; ?

I get ALL kinds of interesting results, I am not sure that any of them are correct. Code Examples would be Helpful.

Thanks so much!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest