|
|
| Author |
Message |
gauret
Joined: 20 Jan 2006 Posts: 3
|
Posted: Sun Jan 28, 2007 12:43 pm Post subject: [HOWTO] Summations other than bandwidth |
|
|
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: | --- 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: | | Total: |gsum:auto:current:2:auto| |
That should do it ! |
|
| Back to top |
|
 |
Cyberwizzard
Joined: 04 Sep 2007 Posts: 8
|
Posted: Tue Sep 04, 2007 11:25 am Post subject: |
|
|
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: | // Fix the multiplication issue
$summation /= 300;
|
And you are set  |
|
| Back to top |
|
 |
colchaodemola
Joined: 18 Feb 2007 Posts: 13
|
Posted: Sun Dec 02, 2007 8:55 pm Post subject: |
|
|
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  |
|
| Back to top |
|
 |
rony Developer/Forum Admin
Joined: 17 Nov 2003 Posts: 5453 Location: Wisconsin, USA
|
Posted: Mon Dec 03, 2007 10:24 am Post subject: |
|
|
| CDEF can not be applied because this value is calculated outside of RRDTool. |
|
| Back to top |
|
 |
ceyounger
Joined: 10 Feb 2006 Posts: 35 Location: San Jose, CA USA
|
Posted: Wed Apr 02, 2008 8:31 pm Post subject: |
|
|
| 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: | // 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! |
|
| Back to top |
|
 |
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|