CDEF Average: ALL SOURCES / NOT NaN sources
Moderators: Developers, Moderators
-
- Posts: 3
- Joined: Wed May 16, 2007 11:26 am
CDEF Average: ALL SOURCES / NOT NaN sources
CDEF Average NOT NaN sources
I have a graph template that pulls data from 42 different data sources. It is a graph showing Index fragmentation from 42 different MSSQL Indexes.
At the bottom of the graph I'd like to calculate the average (fragmentation across the indexes)
I think what I'm looking for is something like:
ALL_DATA_SOURCES_NODUPS / Number of data sources (e.g. 42)
But here's the twist, some of the databases that I use this template on don't have all 42 indexes. For example they have 35 indexes and get NaN values for those other data sources. It is preferable for me to use the superset of indexes rather than make custom graph's for each database.
What would be ideal is if I can create a CDEF function that only counts the number of "NOT NaN" data sources and uses this in the divisor.
Any ideas?
Thanks,
Mike
I have a graph template that pulls data from 42 different data sources. It is a graph showing Index fragmentation from 42 different MSSQL Indexes.
At the bottom of the graph I'd like to calculate the average (fragmentation across the indexes)
I think what I'm looking for is something like:
ALL_DATA_SOURCES_NODUPS / Number of data sources (e.g. 42)
But here's the twist, some of the databases that I use this template on don't have all 42 indexes. For example they have 35 indexes and get NaN values for those other data sources. It is preferable for me to use the superset of indexes rather than make custom graph's for each database.
What would be ideal is if I can create a CDEF function that only counts the number of "NOT NaN" data sources and uses this in the divisor.
Any ideas?
Thanks,
Mike
- gandalf
- Developer
- Posts: 22383
- Joined: Thu Dec 02, 2004 2:46 am
- Location: Muenster, Germany
- Contact:
Find some hints at http://www.vandenbogaerdt.nl
Reinhard
Reinhard
Solution found
I patch it to get this CDEF, total of DS value / total count of DS(NaN counts as 0)
Here's the patch code for cacti/lib/rrd.php
One extra thing I modified is to get total value of data source and count even when data source isn't being graphed. If you don't want that behavior, uncomment this line
and comment out this line in two locations after you patched rrd.php.
Save this patch in a file, and run it under cacti director,
Second step, in include/config_array.php add one additional entry under $custom_data_source_types. Mine looks like this after modification.
Lastly, create the new cdef which should looks like this:
After that, you just need to create a new CDEF from graph management that should look like attached screenshot, and start using it in your graph.
My first time hacking cacti, hope this is the somewhat the right way to do things.
mark
Here's the patch code for cacti/lib/rrd.php
Code: Select all
--- lib/rrd.php 2007-09-26 21:39:54.000000000 +0000
+++ lib/rrd.php 2008-01-10 00:11:17.000000000 +0000
@@ -956,16 +956,19 @@
/* make cdef string here; a note about CDEF's in cacti. A CDEF is neither unique to a
data source of global cdef, but is unique when those two variables combine. */
- $cdef_graph_defs = ""; $cdef_total_ds = ""; $cdef_similar_ds = "";
+ $cdef_graph_defs = ""; $cdef_total_ds = ""; $cdef_similar_ds = "";$cdef_count_ds = "";
if ((!empty($graph_item["cdef_id"])) && (!isset($cdef_cache{$graph_item["cdef_id"]}{$graph_item["data_template_rrd_id"]}[$cf_id]))) {
+
$cdef_string = $graph_variables["cdef_cache"]{$graph_item["graph_templates_item_id"]};
/* create cdef string for "total all data sources" if requested */
if (ereg("ALL_DATA_SOURCES_(NO)?DUPS", $cdef_string)) {
$item_count = 0;
for ($t=0;($t<count($graph_items));$t++) {
- if ((ereg("(AREA|STACK|LINE[123])", $graph_item_types{$graph_items[$t]["graph_type_id"]})) && (!empty($graph_items[$t]["data_template_rrd_id"]))) {
+ // Comment out the following so total can be obtained with actual graph for each item
+ #if ((ereg("(AREA|STACK|LINE[123])", $graph_item_types{$graph_items[$t]["graph_type_id"]})) && (!empty($graph_items[$t]["data_template_rrd_id"]))) {
+ if ( (!empty($graph_items[$t]["data_template_rrd_id"]))) {
/* if the user screws up CF settings, PHP will generate warnings if left unchecked */
if (isset($cf_ds_cache{$graph_items[$t]["data_template_rrd_id"]}[$cf_id])) {
$def_name = generate_graph_def_name(strval($cf_ds_cache{$graph_items[$t]["data_template_rrd_id"]}[$cf_id]));
@@ -982,6 +985,28 @@
}
}
+ /* create cdef string for "total all data sources" if requested */
+ if (ereg("COUNT_OF_KNOWN_DS", $cdef_string)) {
+ $item_count = 0;
+ for ($t=0;($t<count($graph_items));$t++) {
+ #if ((ereg("(AREA|STACK|LINE[123])", $graph_item_types{$graph_items[$t]["graph_type_id"]})) && (!empty($graph_items[$t]["data_template_rrd_id"]))) {
+ if ( (!empty($graph_items[$t]["data_template_rrd_id"])) ) {
+ /* if the user screws up CF settings, PHP will generate warnings if left unchecked */
+ if (isset($cf_ds_cache{$graph_items[$t]["data_template_rrd_id"]}[$cf_id])) {
+ $def_name = generate_graph_def_name(strval($cf_ds_cache{$graph_items[$t]["data_template_rrd_id"]}[$cf_id]));
+ $cdef_count_ds .= ($item_count == 0 ? "" : ",") . "TIME," . (time() - $seconds_between_graph_updates) . ",GT,1,$def_name,UN,0,1,IF,IF"; /* convert unknowns to '0' first */
+ $item_count++;
+ }
+ }
+ }
+
+ /* if there is only one item to total, don't even bother with the summation. otherwise
+ cdef=a,b,c,+,+ is fine. */
+ if ($item_count > 1) {
+ $cdef_count_ds .= str_repeat(",+", ($item_count - 2)) . ",+";
+ }
+ }
+
/* create cdef string for "total similar data sources" if requested */
if (ereg("SIMILAR_DATA_SOURCES_(NO)?DUPS", $cdef_string) ) {
$sources_seen = array();
@@ -1009,6 +1034,7 @@
$cdef_string = str_replace("CURRENT_DATA_SOURCE", generate_graph_def_name(strval((isset($cf_ds_cache{$graph_item["data_template_rrd_id"]}[$cf_id]) ? $cf_ds_cache{$graph_item["data_template_rrd_id"]}[$cf_id] : "0"))), $cdef_string);
$cdef_string = str_replace("ALL_DATA_SOURCES_NODUPS", $cdef_total_ds, $cdef_string);
$cdef_string = str_replace("SIMILAR_DATA_SOURCES_NODUPS", $cdef_similar_ds, $cdef_string);
+ $cdef_string = str_replace("COUNT_OF_KNOWN_DS", $cdef_count_ds, $cdef_string);
/* data source item variables */
$cdef_string = str_replace("CURRENT_DS_MINIMUM_VALUE", (empty($graph_item["rrd_minimum"]) ? "0" : $graph_item["rrd_minimum"]), $cdef_string);
@@ -1166,4 +1192,4 @@
}
}
-?>
\ No newline at end of file
+?>
Code: Select all
#if ((ereg("(AREA|STACK|LINE[123])", $graph_item_types{$graph_items[$t]["graph_type_id"]})) && (!empty($graph_items[$t]["data_template_rrd_id"]))) {
Code: Select all
if ( (!empty($graph_items[$t]["data_template_rrd_id"]))) {
Code: Select all
patch -p1 <patch.file
Code: Select all
$custom_data_source_types = array(
"CURRENT_DATA_SOURCE" => "Current Graph Item Data Source",
"ALL_DATA_SOURCES_NODUPS" => "All Data Sources (Don't Include Duplicates)",
"ALL_DATA_SOURCES_DUPS" => "All Data Sources (Include Duplicates)",
"COUNT_OF_KNOWN_DS" => "Count of DS with Known Value",
"CURRENT_DS_MINIMUM_VALUE" => "Current Data Source Item: Minimum Value",
"SIMILAR_DATA_SOURCES_NODUPS" => "All Similar Data Sources (Don't Include Duplicates)",
"CURRENT_DS_MAXIMUM_VALUE" => "Current Data Source Item: Maximum Value",
"CURRENT_GRAPH_MINIMUM_VALUE" => "Graph: Lower Limit",
"CURRENT_GRAPH_MAXIMUM_VALUE" => "Graph: Upper Limit");
Code: Select all
"COUNT_OF_KNOWN_DS" => "Count of DS with Known Value",
My first time hacking cacti, hope this is the somewhat the right way to do things.
mark
- Attachments
-
- screenshot
- Picture 1.png (30.11 KiB) Viewed 3913 times
- gandalf
- Developer
- Posts: 22383
- Joined: Thu Dec 02, 2004 2:46 am
- Location: Muenster, Germany
- Contact:
Nice, indeed. Please post a feature request as given by http://www.cacti.net/bugs.php. This insures a possible integration into main cacti code
Reinhard
Reinhard
-
- Cacti User
- Posts: 234
- Joined: Mon Dec 13, 2004 3:03 pm
- gandalf
- Developer
- Posts: 22383
- Joined: Thu Dec 02, 2004 2:46 am
- Location: Muenster, Germany
- Contact:
I'm not aware of a report as required from http://www.cacti.net/bugs.php
As I already said, I'm quite positive for implementing it. I only need the bug report for tracking
Reinhard
As I already said, I'm quite positive for implementing it. I only need the bug report for tracking
Reinhard
-
- Cacti User
- Posts: 234
- Joined: Mon Dec 13, 2004 3:03 pm
Who is online
Users browsing this forum: macan and 5 guests