CDEF Average: ALL SOURCES / NOT NaN sources

Post general support questions here that do not specifically fall into the Linux or Windows categories.

Moderators: Developers, Moderators

Post Reply
mp72@excite.com
Posts: 3
Joined: Wed May 16, 2007 11:26 am

CDEF Average: ALL SOURCES / NOT NaN sources

Post by mp72@excite.com »

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
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

Find some hints at http://www.vandenbogaerdt.nl
Reinhard
kuma3
Posts: 25
Joined: Tue Oct 02, 2007 1:17 pm

Solution found

Post by kuma3 »

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

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
+?>
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

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"]))) {
and comment out this line in two locations after you patched rrd.php.

Code: Select all

                                       if ( (!empty($graph_items[$t]["data_template_rrd_id"]))) {
Save this patch in a file, and run it under cacti director,

Code: Select all

patch -p1 <patch.file
Second step, in include/config_array.php add one additional entry under $custom_data_source_types. Mine looks like this after modification.

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");
Lastly, create the new cdef which should looks like this:

Code: Select all

"COUNT_OF_KNOWN_DS" => "Count of DS with Known Value",
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
Attachments
screenshot
screenshot
Picture 1.png (30.11 KiB) Viewed 3911 times
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

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
X505
Posts: 39
Joined: Fri Jun 29, 2007 3:53 pm
Contact:

Post by X505 »

kuma3, thank you VERY much.
your patch does not work on the 0.8.7b but hand made patch works :D

here is the result (average of 20 IBM bladecenter back temp) :

Before:
Image

After:
Image


If kuma3 is ok, i can provide the patch for 0.8.7b if someone need it

8)
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

If kuma added the bug report, please add it there. Else open your own and add the code
Reinhard
eschoeller
Cacti User
Posts: 234
Joined: Mon Dec 13, 2004 3:03 pm

Post by eschoeller »

X505: What does your graph template look like for the BladeCenter Averages.?

Has this patch been mainlined?
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

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
eschoeller
Cacti User
Posts: 234
Joined: Mon Dec 13, 2004 3:03 pm

Post by eschoeller »

This has a bug report now

http://bugs.cacti.net/view.php?id=1249
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

-feature#0001249: New pseudo CDEF variables for "Count All|Similar Data Sources (NO)?DUPS"
will be available with 087c soon
Reinhard
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests