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,
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|