Cacti (home)ForumsRepositoryDocumentation
Cacti: offical forums and support  

 FAQFAQ   SearchSearch   MemberlistMemberlist    RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in    


DEF:a="/var/www/html/cacti/rra/localhost/traffic_in/29.
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cacti Forum Index -> Help: Unstable Development Versions
Author Message
oxo-oxo
Cacti User


Joined: 30 Aug 2007
Posts: 113
Location: Silkeborg, Denmark

PostPosted: Fri Sep 07, 2007 10:47 am    Post subject: DEF:a="/var/www/html/cacti/rra/localhost/traffic_in/29. Reply with quote

I'm playing with rrd: this post discusses '/' instead of _:
ie
Quote:
DEF:a="/var/www/html/cacti/rra/localhost/traffic_in/29.rrd":traffic_in:AVERAGE \

It makes for a less confusing rra root dir when one uses directory structure.

Status: Working
Code diffs in http://forums.cacti.net/viewtopic.php?p=110301#110301
Otherwise as attachment
NB:
- that code base is from SVN so note the revision I'm using.
- contains \ contra / with test of os: Windows untested.

Well there is also another more masacistic (better in many ways) code here- see further down the post...

Conclussion (at least for me):I
It is possible to make use of dirs.
It can also make referencing the rrd's easier from other programs ...
One point of design should be that the poller only makes dirs after it's finished its polling (or else the poller time will vary to much). So this is done.

At the moment, making rrd dirs is sent when the graph is created.
A refresh rrd_dirs is also here http://forums.cacti.net/viewtopic.php?p=110435#110435

I prefer naming rrd_path after ID's, see latter in this post.

Unfortunatly, a new cacti.sql had to be made in connection with poller_command but a small price to pay ... (or else drop POLLER_ cmd and update the directory structure with the enclosed rebuild rrd dir cli)

ToDo:
- nice to have: switch in GUI for flat or structured rra (me: I like a hidden config entry, $config["oxo_rrd_dir"] so I stop there)

Referance:
http://forums.cacti.net/viewtopic.php?p=73353#73353

Security
Well I guess that the rra could be ro mounted by the cacti webserver.
The poller writes data to the rra but the web can't make dir's.
So a POLLER_COMMAND is made and poller_command process's a limit(-ed) number of mkdirs to ensure it doesn't overrun it's time.

More than one poller machine:
And there could be more than one poller that exists on different physical machines: which means that the structure should be:
<poller id>/<host id>/ etc ..
Not addressed. yet

Naming
Hostname contra host id
Which would also address that host id can be changed by user, but not reflect in structure ...
There is a version here that used id instead of hostname. The poller_item is dumped for documentation in the rrd dir.
Quote:
DEF:a="/var/www/html/cacti/rra/2/173/59.rrd":mem_buffers:AVERAGE \

Code Diffs here http://forums.cacti.net/viewtopic.php?p=110434#110434
rra with "host id" is probably the code I will keep working on as it better to referance with ID's contra hostname. So it is attached.



cacti-oxo.tgz
 Description:
Complete cacti with patches (SVN 4144)
See README-oxo

Download
 Filename:  cacti-oxo.tgz
 Filesize:  1.23 MB
 Downloaded:  250 Time(s)



Last edited by oxo-oxo on Mon Sep 10, 2007 11:09 pm; edited 49 times in total
Back to top
shull
Cacti User


Joined: 24 Aug 2006
Posts: 54
Location: South Texas

PostPosted: Fri Sep 07, 2007 12:27 pm    Post subject: Reply with quote

So this one RRD file will possibly contain many sets of data within one (larger) RRA? If so, that's pretty cool. It would definitly help in the organization of the files.

-Stephen
Back to top
oxo-oxo
Cacti User


Joined: 30 Aug 2007
Posts: 113
Location: Silkeborg, Denmark

PostPosted: Fri Sep 07, 2007 12:31 pm    Post subject: Reply with quote

No, sorry.

Code:

"<path_rra>/$host_part$ds_part" . "/" . "$local_data_id.rrd";


a number of host_ds directories, each containing a number of rrd directories

But means the root of <path_rra> isn't as cluttered.
Back to top
TheWitness
Developer


Joined: 14 May 2002
Posts: 9736
Location: MI, USA

PostPosted: Fri Sep 07, 2007 12:48 pm    Post subject: Reply with quote

Already been done. Look to add-on's and you will find it. I think it's something like "structured rrd path patch".

TheWitness
Back to top
oxo-oxo
Cacti User


Joined: 30 Aug 2007
Posts: 113
Location: Silkeborg, Denmark

PostPosted: Fri Sep 07, 2007 12:57 pm    Post subject: Reply with quote

Yes, but it ends with:
http://forums.cacti.net/viewtopic.php?t=15025&postdays=0&postorder=asc&highlight=structured+rrd+path+patch&start=15

Is it in the pipeline for Version 0.8.7 ...

I need it.

Anyway, I need the practise

I'll get back to cli/add_<function> after this, it is just that I'm getting tired of all the rrd files
Back to top
TheWitness
Developer


Joined: 14 May 2002
Posts: 9736
Location: MI, USA

PostPosted: Fri Sep 07, 2007 4:44 pm    Post subject: Reply with quote

Ok, cool. 0.8.7. Hmm. That was the "other" 0.8.7

TheWitness
Back to top
oxo-oxo
Cacti User


Joined: 30 Aug 2007
Posts: 113
Location: Silkeborg, Denmark

PostPosted: Sat Sep 08, 2007 12:57 pm    Post subject: Reply with quote

functions for making dirs
POLLER_COMMAND for instructing the poller to make dirs via insert poller_command
Seperator $sep added for _ or /
"Hidden" $config["oxo_rrd_dir"] to control $sep and insert poller_command

Code:

Index: cacti.sql
===================================================================
--- cacti.sql   (revision 4134)
+++ cacti.sql   (working copy)
@@ -2041,11 +2041,12 @@
 --

 CREATE TABLE poller_command (
+  id mediumint(8) unsigned NOT NULL auto_increment,
   poller_id smallint(5) unsigned NOT NULL default '0',
   time datetime NOT NULL default '0000-00-00 00:00:00',
   action tinyint(3) unsigned NOT NULL default '0',
   command varchar(200) NOT NULL default '',
-  PRIMARY KEY  (poller_id,action,command)
+  PRIMARY KEY  (id)
 ) TYPE=MyISAM;

 --
@@ -2619,4 +2620,4 @@
 -- Dumping data for table `version`
 --

-INSERT INTO version VALUES ('new_install');
\ No newline at end of file
+INSERT INTO version VALUES ('new_install');

Index: lib/functions.php
===================================================================
--- lib/functions.php   (revision 4134)
+++ lib/functions.php   (working copy)
@@ -943,13 +943,25 @@
    @arg $local_data_id - (int) the ID of the data source to generate a new path for
    @returns - the new generated path */
 function generate_data_source_path($local_data_id) {
+       global $config;
+
        $host_part = ""; $ds_part = "";

+        if (isset($config["oxo_rrd_dir"])) {
+               if ($config["cacti_server_os"] == "unix") {
+                       $sep = '/';
+               }else{
+                       $sep = '\\'; //untested for Windows
+               }
+        }else{
+                $sep = '_';
+        }
+
        /* try any prepend the name with the host description */
        $host_name = db_fetch_cell("select host.description from (host,data_local) where data_local.host_id=host.id and data_local.id=$local_data_id");

        if (!empty($host_name)) {
-               $host_part = strtolower(clean_up_file_name($host_name)) . "_";
+               $host_part = strtolower(clean_up_file_name($host_name)) . $sep;
        }

        /* then try and use the internal DS name to identify it */
@@ -962,7 +974,7 @@
        }

        /* put it all together using the local_data_id at the end */
-       $new_path = "<path_rra>/$host_part$ds_part" . "_" . "$local_data_id.rrd";
+       $new_path = "<path_rra>" . $sep . $host_part . $ds_part . $sep . $local_data_id . ".rrd";

        /* update our changes to the db */
        db_execute("update data_template_data set data_source_path='$new_path' where local_data_id=$local_data_id");
@@ -970,6 +982,31 @@
        return $new_path;
 }

+/* generate_data_source_dirs - creates  data source directory path for a $rrc_path
+   @arg rrd_path - (string) the path of the rrd
+   @returns - true if OK (found or created */
+#OXO
+function generate_data_source_dirs($rrd_path) {
+       /* strip filename if there: however is it good enough just to test for . ? */
+       strstr($rrd_path, '.') ? $nextdir = dirname($rrd_path) : $nextdir = $rrd_path;
+       @mkdir($nextdir,0777,true);
+       return file_exists($nextdir);
+}
+
+/* makeDirs - takes a path (without filename) and makes the path
+   @arg $strPath - (string) the path without filename
+   @arg $mode - (int) mode for creation, default 0776
+   @returns - I hope. Not to good: could go forever : need test for stop... */
+function makeDirs($strPath, $mode = 0766) {
+               $pardir = dirname($strPath);
+               if (!(($strPath == '/') || ($strPath == '.'))){
+                       makeDirs($pardir, $mode);
+               }
+               echo "$strPath\n";
+               chdir($pardir);
+               return @mkdir($strPath, $mode);
+}
+
 /* generate_graph_def_name - takes a number and turns each digit into its letter-based
      counterpart for RRDTool DEF names (ex 1 -> a, 2 -> b, etc)
    @arg $graph_item_id - (int) the ID to generate a letter-based representation of

Index: lib/api_poller.php
===================================================================
--- lib/api_poller.php  (revision 4134)
+++ lib/api_poller.php  (working copy)
@@ -23,6 +23,8 @@
 */

 function api_poller_cache_item_add($host_id, $host_field_override, $local_data_id, $rrd_step, $poller_action_id, $data_source_item_name, $num_rrd_items, $arg1 = "", $arg2 = "", $arg3 = "") {
+       global $config;
+
        $host = db_fetch_row("select
                host.id,
                host.hostname,
@@ -75,7 +77,13 @@
                }

                $rrd_next_step = api_poller_get_rrd_next_step($rrd_step, $num_rrd_items);
+#OXO
+               $rrd_path = addslashes(clean_up_path(get_data_source_path($local_data_id, true)));

+               if (isset($config["oxo_rrd_dir"])) {
+                       db_execute("insert into poller_command (poller_id, time, action, command) values (0, NOW(), " . POLLER_COMMAND_MAKE_RDD_DIRS . ",'" . $rrd_path . "')");
+               }
+
                return db_execute("INSERT INTO poller_item (local_data_id, host_id, action,hostname,
                        snmp_community, snmp_version, snmp_timeout, snmp_username, snmp_password,
                        snmp_auth_protocol, snmp_priv_passphrase, snmp_priv_protocol, snmp_port, rrd_name, rrd_path,
@@ -85,7 +93,7 @@
                        '" . $host["snmp_community"]       . "', '" . $host["snmp_version"]       . "', '" . $host["snmp_timeout"] . "',
                        '" . $host["snmp_username"]        . "', '" . $host["snmp_password"]      . "', '" . $host["snmp_auth_protocol"] . "',
                        '" . $host["snmp_priv_passphrase"] . "', '" . $host["snmp_priv_protocol"] . "',
-                       '" . $host["snmp_port"]            . "', '$data_source_item_name', '"     . addslashes(clean_up_path(get_data_source_path($local_data_id, true))) . "',
+                       '" . $host["snmp_port"]            . "', '$data_source_item_name', '" . $rrd_path . "',
                        '$num_rrd_items', '$rrd_step', '$rrd_next_step', '$arg1', '$arg2', '$arg3')");
        }
 }
@@ -136,4 +144,4 @@

        return $rrd_next_step;
 }
-?>
\ No newline at end of file
+?>
Index: include/global_constants.php
===================================================================
--- include/global_constants.php        (revision 4134)
+++ include/global_constants.php        (working copy)
@@ -61,6 +61,7 @@

 define("POLLER_COMMAND_REINDEX", 1);
 define("POLLER_COMMAND_RRDPURGE", 2);
+define("POLLER_COMMAND_MAKE_RDD_DIRS", 3);

 define("POLLER_VERBOSITY_NONE", 1);
 define("POLLER_VERBOSITY_LOW", 2);
@@ -162,4 +163,4 @@
 define("SNMP_CMDPHP", 1);
 define("SNMP_WEBUI", 2);

-?>
\ No newline at end of file
+?>
Index: include/global.php
===================================================================
--- include/global.php  (revision 4134)
+++ include/global.php  (working copy)
@@ -180,4 +180,7 @@
 /* current cacti version */
 $config["cacti_version"] = "0.8.7";

+/* oxo hack */
+
+$config["oxo_rrd_dir"] = "1";
 ?>
Index: poller_commands.php
===================================================================
--- poller_commands.php (revision 4134)
+++ poller_commands.php (working copy)
@@ -37,21 +37,24 @@
 include_once($config["base_path"] . "/lib/poller.php");
 include_once($config["base_path"] . "/lib/data_query.php");
 include_once($config["base_path"] . "/lib/rrd.php");
+include_once($config["base_path"] . "/lib/functions.php");

 /* Record Start Time */
 list($micro,$seconds) = split(" ", microtime());
 $start = $seconds + $micro;

 $poller_commands = db_fetch_assoc("select
+       poller_command.id,
        poller_command.action,
        poller_command.command
        from poller_command
-       where poller_command.poller_id=0");
+       where poller_command.poller_id=0 limit 0, 9");

 $last_host_id = 0;
 $first_host = true;
 $recached_hosts = 0;

+#OXO
 if (sizeof($poller_commands) > 0) {
        foreach ($poller_commands as $command) {
                switch ($command["action"]) {
@@ -79,6 +82,16 @@
                                cacti_log("Host[$host_id] RECACHE: Re-cache successful.", true, "PCOMMAND");
                        }
                        break;
+               case POLLER_COMMAND_MAKE_RDD_DIRS:
+                       $rrd_path = $command["command"];
+                       if (generate_data_source_dirs($rrd_path)) {
+                               if (read_config_option("log_verbosity") == POLLER_VERBOSITY_DEBUG) {
+                                       cacti_log("$rrd_path MAKE_RDD_PATHS: Make dirs successful. MAYBE", true, "PCOMMAND");
+                               }
+                       } else {
+                               cacti_log("ERROR: MAKE_RDD_DIRS " . $rrd_path, true, "PCOMMAND");
+                       }
+                       break;
                default:
                        cacti_log("ERROR: Unknown poller command issued", true, "PCOMMAND");
                }
@@ -92,9 +105,10 @@
                        cacti_log("ERROR: Poller Command processing timed out after processing '" . $command . "'",true,"PCOMMAND");
                        break;
                }
+               db_execute("delete from poller_command where id=" . $command["id"]);
        }
-
-       db_execute("delete from poller_command where poller_id=0");
+
+       #db_execute("delete from poller_command where poller_id=0");
 }

 /* take time to log performance data */


Last edited by oxo-oxo on Mon Sep 10, 2007 2:21 pm; edited 12 times in total
Back to top
oxo-oxo
Cacti User


Joined: 30 Aug 2007
Posts: 113
Location: Silkeborg, Denmark

PostPosted: Mon Sep 10, 2007 10:19 am    Post subject: Reply with quote

Suk ...
Code:
Index: cacti.sql
===================================================================
--- cacti.sql   (revision 4134)
+++ cacti.sql   (working copy)
@@ -2041,11 +2041,12 @@
 --

 CREATE TABLE poller_command (
+  id mediumint(8) unsigned NOT NULL auto_increment,
   poller_id smallint(5) unsigned NOT NULL default '0',
   time datetime NOT NULL default '0000-00-00 00:00:00',
   action tinyint(3) unsigned NOT NULL default '0',
   command varchar(200) NOT NULL default '',
-  PRIMARY KEY  (poller_id,action,command)
+  PRIMARY KEY  (id)
 ) TYPE=MyISAM;

 --
@@ -2619,4 +2620,4 @@
 -- Dumping data for table `version`
 --

-INSERT INTO version VALUES ('new_install');
\ No newline at end of file
+INSERT INTO version VALUES ('new_install');
Back to top
oxo-oxo
Cacti User


Joined: 30 Aug 2007
Posts: 113
Location: Silkeborg, Denmark

PostPosted: Mon Sep 10, 2007 2:04 pm    Post subject: Reply with quote

Start of:
Quote:
Cacti Rebuild RRD DIR Script 1.0, Copyright 2007 - The Cacti Group
Code:
<?php
/*
 +-------------------------------------------------------------------------+
 | Copyright (C) 2004-2007 The Cacti Group                                 |
 ?>


But cut out here as it comes in a latter post...


Last edited by oxo-oxo on Mon Sep 10, 2007 3:33 pm; edited 1 time in total
Back to top
oxo-oxo
Cacti User


Joined: 30 Aug 2007
Posts: 113
Location: Silkeborg, Denmark

PostPosted: Mon Sep 10, 2007 2:41 pm    Post subject: Reply with quote

For the masacistic (now I do need a txt file for the dirs):

Quote:
-bash-3.1$ ls -R rra
rra:
2

rra/2:
173 174 175 177 179

rra/2/173:
59.rrd

rra/2/174:
60.rrd

rra/2/175:
61.rrd

rra/2/177:
62.rrd

rra/2/179:
63.rrd


Code:
Index: cacti.sql
===================================================================
--- cacti.sql   (revision 4134)
+++ cacti.sql   (working copy)
@@ -2041,11 +2041,12 @@
 --

 CREATE TABLE poller_command (
+  id mediumint(8) unsigned NOT NULL auto_increment,
   poller_id smallint(5) unsigned NOT NULL default '0',
   time datetime NOT NULL default '0000-00-00 00:00:00',
   action tinyint(3) unsigned NOT NULL default '0',
   command varchar(200) NOT NULL default '',
-  PRIMARY KEY  (poller_id,action,command)
+  PRIMARY KEY  (id)
 ) TYPE=MyISAM;

 --
@@ -2619,4 +2620,4 @@
 -- Dumping data for table `version`
 --

-INSERT INTO version VALUES ('new_install');
\ No newline at end of file
+INSERT INTO version VALUES ('new_install');
Index: lib/functions.php
===================================================================
--- lib/functions.php   (revision 4134)
+++ lib/functions.php   (working copy)
@@ -943,17 +943,29 @@
    @arg $local_data_id - (int) the ID of the data source to generate a new path for
    @returns - the new generated path */
 function generate_data_source_path($local_data_id) {
+       global $config;
+
        $host_part = ""; $ds_part = "";

+        if (isset($config["oxo_rrd_dir"])) {
+               if ($config["cacti_server_os"] == "unix") {
+                       $sep = '/';
+               }else{
+                       $sep = '\\'; //untested for Windows
+               }
+        }else{
+                $sep = '_';
+        }
+
        /* try any prepend the name with the host description */
-       $host_name = db_fetch_cell("select host.description from (host,data_local) where data_local.host_id=host.id and data_local.id=$local_data_id");
+       $host_name = db_fetch_cell("select host.id from (host,data_local) where data_local.host_id=host.id and data_local.id=$local_data_id");

        if (!empty($host_name)) {
-               $host_part = strtolower(clean_up_file_name($host_name)) . "_";
+               $host_part = strtolower(clean_up_file_name($host_name)) . $sep;
        }

        /* then try and use the internal DS name to identify it */
-       $data_source_rrd_name = db_fetch_cell("select data_source_name from data_template_rrd where local_data_id=$local_data_id order by id");
+       $data_source_rrd_name = db_fetch_cell("select id from data_template_rrd where local_data_id=$local_data_id order by id");

        if (!empty($data_source_rrd_name)) {
                $ds_part = strtolower(clean_up_file_name($data_source_rrd_name));
@@ -962,7 +974,7 @@
        }

        /* put it all together using the local_data_id at the end */
-       $new_path = "<path_rra>/$host_part$ds_part" . "_" . "$local_data_id.rrd";
+       $new_path = "<path_rra>" . $sep . $host_part . $ds_part . $sep . $local_data_id . ".rrd";

        /* update our changes to the db */
        db_execute("update data_template_data set data_source_path='$new_path' where local_data_id=$local_data_id");
@@ -970,6 +982,31 @@
        return $new_path;
 }

+/* generate_data_source_dirs - creates  data source directory path for a $rrc_path
+   @arg rrd_path - (string) the path of the rrd
+   @returns - true if OK (found or created */
+#OXO
+function generate_data_source_dirs($rrd_path) {
+       /* strip filename if there: however is it good enough just to test for . ? */
+       strstr($rrd_path, '.') ? $nextdir = dirname($rrd_path) : $nextdir = $rrd_path;
+       @mkdir($nextdir,0777,true);
+       return file_exists($nextdir);
+}
+
+/* makeDirs - takes a path (without filename) and makes the path
+   @arg $strPath - (string) the path without filename
+   @arg $mode - (int) mode for creation, default 0776
+   @returns - I hope. Not to good: could go forever : need test for stop... */
+function makeDirs($strPath, $mode = 0766) {
+               $pardir = dirname($strPath);
+               if (!(($strPath == '/') || ($strPath == '.'))){
+                       makeDirs($pardir, $mode);
+               }
+               echo "$strPath\n";
+               chdir($pardir);
+               return @mkdir($strPath, $mode);
+}
+
 /* generate_graph_def_name - takes a number and turns each digit into its letter-based
      counterpart for RRDTool DEF names (ex 1 -> a, 2 -> b, etc)
    @arg $graph_item_id - (int) the ID to generate a letter-based representation of
Index: lib/api_poller.php
===================================================================
--- lib/api_poller.php  (revision 4134)
+++ lib/api_poller.php  (working copy)
@@ -23,6 +23,8 @@
 */

 function api_poller_cache_item_add($host_id, $host_field_override, $local_data_id, $rrd_step, $poller_action_id, $data_source_item_name, $num_rrd_items, $arg1 = "", $arg2 = "", $arg3 = "") {
+       global $config;
+
        $host = db_fetch_row("select
                host.id,
                host.hostname,
@@ -75,7 +77,13 @@
                }

                $rrd_next_step = api_poller_get_rrd_next_step($rrd_step, $num_rrd_items);
+#OXO
+               $rrd_path = addslashes(clean_up_path(get_data_source_path($local_data_id, true)));

+               if (isset($config["oxo_rrd_dir"])) {
+                       db_execute("insert into poller_command (poller_id, time, action, command) values (0, NOW(), " . POLLER_COMMAND_MAKE_RDD_DIRS . ",'" . $rrd_path . "')");
+               }
+
                return db_execute("INSERT INTO poller_item (local_data_id, host_id, action,hostname,
                        snmp_community, snmp_version, snmp_timeout, snmp_username, snmp_password,
                        snmp_auth_protocol, snmp_priv_passphrase, snmp_priv_protocol, snmp_port, rrd_name, rrd_path,
@@ -85,7 +93,7 @@
                        '" . $host["snmp_community"]       . "', '" . $host["snmp_version"]       . "', '" . $host["snmp_timeout"] . "',
                        '" . $host["snmp_username"]        . "', '" . $host["snmp_password"]      . "', '" . $host["snmp_auth_protocol"] . "',
                        '" . $host["snmp_priv_passphrase"] . "', '" . $host["snmp_priv_protocol"] . "',
-                       '" . $host["snmp_port"]            . "', '$data_source_item_name', '"     . addslashes(clean_up_path(get_data_source_path($local_data_id, true))) . "',
+                       '" . $host["snmp_port"]            . "', '$data_source_item_name', '" . $rrd_path . "',
                        '$num_rrd_items', '$rrd_step', '$rrd_next_step', '$arg1', '$arg2', '$arg3')");
        }
 }
@@ -136,4 +144,4 @@

        return $rrd_next_step;
 }
-?>
\ No newline at end of file
+?>
Index: include/global_constants.php
===================================================================
--- include/global_constants.php        (revision 4134)
+++ include/global_constants.php        (working copy)
@@ -61,6 +61,7 @@

 define("POLLER_COMMAND_REINDEX", 1);
 define("POLLER_COMMAND_RRDPURGE", 2);
+define("POLLER_COMMAND_MAKE_RDD_DIRS", 3);

 define("POLLER_VERBOSITY_NONE", 1);
 define("POLLER_VERBOSITY_LOW", 2);
@@ -162,4 +163,4 @@
 define("SNMP_CMDPHP", 1);
 define("SNMP_WEBUI", 2);

-?>
\ No newline at end of file
+?>
Index: include/global.php
===================================================================
--- include/global.php  (revision 4134)
+++ include/global.php  (working copy)
@@ -180,4 +180,7 @@
 /* current cacti version */
 $config["cacti_version"] = "0.8.7";

+/* oxo hack */
+
+$config["oxo_rrd_dir"] = "1";
 ?>
Index: poller_commands.php
===================================================================
--- poller_commands.php (revision 4134)
+++ poller_commands.php (working copy)
@@ -37,21 +37,24 @@
 include_once($config["base_path"] . "/lib/poller.php");
 include_once($config["base_path"] . "/lib/data_query.php");
 include_once($config["base_path"] . "/lib/rrd.php");
+include_once($config["base_path"] . "/lib/functions.php");

 /* Record Start Time */
 list($micro,$seconds) = split(" ", microtime());
 $start = $seconds + $micro;

 $poller_commands = db_fetch_assoc("select
+       poller_command.id,
        poller_command.action,
        poller_command.command
        from poller_command
-       where poller_command.poller_id=0");
+       where poller_command.poller_id=0 limit 0, 9");

 $last_host_id = 0;
 $first_host = true;
 $recached_hosts = 0;

+#OXO
 if (sizeof($poller_commands) > 0) {
        foreach ($poller_commands as $command) {
                switch ($command["action"]) {
@@ -79,6 +82,16 @@
                                cacti_log("Host[$host_id] RECACHE: Re-cache successful.", true, "PCOMMAND");
                        }
                        break;
+               case POLLER_COMMAND_MAKE_RDD_DIRS:
+                       $rrd_path = $command["command"];
+                       if (generate_data_source_dirs($rrd_path)) {
+                               if (read_config_option("log_verbosity") == POLLER_VERBOSITY_DEBUG) {
+                                       cacti_log("$rrd_path MAKE_RDD_PATHS: Make dirs successful. MAYBE", true, "PCOMMAND");
+                               }
+                       } else {
+                               cacti_log("ERROR: MAKE_RDD_DIRS " . $rrd_path, true, "PCOMMAND");
+                       }
+                       break;
                default:
                        cacti_log("ERROR: Unknown poller command issued", true, "PCOMMAND");
                }
@@ -92,9 +105,10 @@
                        cacti_log("ERROR: Poller Command processing timed out after processing '" . $command . "'",true,"PCOMMAND");
                        break;
                }
+               db_execute("delete from poller_command where id=" . $command["id"]);
        }
-
-       db_execute("delete from poller_command where poller_id=0");
+
+       #db_execute("delete from poller_command where poller_id=0");
 }

 /* take time to log performance data */
Back to top
oxo-oxo
Cacti User


Joined: 30 Aug 2007
Posts: 113
Location: Silkeborg, Denmark

PostPosted: Mon Sep 10, 2007 3:15 pm    Post subject: Reply with quote

Generating documentation in an rrd dir was ok so here it is with the rebuild rrd_paths
One may need to filter the info

Quote:
-bash-3.1$ cat rra/2/173/59.rrd.txt
Array
(
[local_data_id] => 59
[poller_id] => 0
[host_id] => 2
[action] => 1
[hostname] => localhost
[snmp_community] => public
[snmp_version] => 2
[snmp_username] =>
[snmp_password] =>
[snmp_auth_protocol] => MD5
[snmp_priv_passphrase] =>
[snmp_priv_protocol] => DES
[snmp_port] => 161
[snmp_timeout] => 500
[rrd_name] => mem_buffers
[rrd_path] => /var/www/html/cacti/rra/2/173/59.rrd
[rrd_num] => 1
[rrd_step] => 300
[rrd_next_step] => 0
[arg1] => perl /var/www/html/cacti/scripts/linux_memory.pl MemFree:
[arg2] =>
[arg3] =>
)

Quote:
-bash-3.1$ ls -R rra
rra:
2

rra/2:
173 174 175 177 179

rra/2/173:
59.rrd 59.rrd.txt

rra/2/174:
60.rrd 60.rrd.txt

rra/2/175:
61.rrd 61.rrd.txt

rra/2/177:
62.rrd 62.rrd.txt

rra/2/179:
63.rrd 63.rrd.txt

Code:
-bash-3.1$ cat cli/rebuild_rrd_dir.php
<?php
/*
 +-------------------------------------------------------------------------+
 | Copyright (C) 2004-2007 The Cacti Group                                 |
 |                                                                         |
 | This program is free software; you can redistribute it and/or           |
 | modify it under the terms of the GNU General Public License             |
 | as published by the Free Software Foundation; either version 2          |
 | of the License, or (at your option) any later version.                  |
 |                                                                         |
 | This program is distributed in the hope that it will be useful,         |
 | but WITHOUT ANY WARRANTY; without even the implied warranty of          |
 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           |
 | GNU General Public License for more details.                            |
 +-------------------------------------------------------------------------+
 | Cacti: The Complete RRDTool-based Graphing Solution                     |
 +-------------------------------------------------------------------------+
 | This code is designed, written, and maintained by the Cacti Group. See  |
 | about.php and/or the AUTHORS file for specific developer information.   |
 +-------------------------------------------------------------------------+
 | http://www.cacti.net/                                                   |
 +-------------------------------------------------------------------------+
*/

/* do NOT run this script through a web browser */
if (!isset($_SERVER["argv"][0]) || isset($_SERVER['REQUEST_METHOD'])  || isset($_SERVER['REMOTE_ADDR'])) {
        die("<br><strong>This script is only meant to run at the command line.</strong>");
}

$no_http_headers = true;

include(dirname(__FILE__) . "/../include/global.php");
include_once($config["base_path"] . "/lib/utility.php");

/* process calling arguments */
$parms = $_SERVER["argv"];
array_shift($parms);

$debug = FALSE;

foreach($parms as $parameter) {
        @list($arg, $value) = @explode("=", $parameter);

        switch ($arg) {
        case "-d":
                $debug = TRUE;
                break;
        case "-h":
                display_help();
                exit;
        case "-v":
                display_help();
                exit;
        case "--version":
                display_help();
                exit;
        case "--help":
                display_help();
                exit;
        default:
                print "ERROR: Invalid Parameter " . $parameter . "\n\n";
                display_help();
                exit;
        }
}

/* obtain timeout settings */
$max_execution = ini_get("max_execution_time");
$max_memory = ini_get("memory_limit");

/* set new timeout and memory settings */
ini_set("max_execution_time", "0");
ini_set("memory_limit", "64M");


/* get the poller items */
$poller_items = db_fetch_assoc("select * from poller_item");

/* issue warnings and start message if applicable */
print "WARNING: Do not interrupt this script.  Rebuilding the RRD directories can take quite some time\n";
debug("There are '" . sizeof($poller_items) . "' poller items to update.");

if (sizeof($poller_items) > 0) {
        foreach ($poller_items as $item) {
                generate_data_source_dirs($item["rrd_path"]);
                $rrd_txt_file = $item["rrd_path"] . ".txt";
                $item_array = print_r($item, true);
                file_put_contents($rrd_txt_file, $item_array);
        }
}

if (!$debug) print "\n";

/* poller cache rebuilt, restore runtime parameters */
ini_set("max_execution_time", $max_execution);
ini_set("memory_limit", $max_memory);

/*      display_help - displays the usage of the function */
function display_help () {
        print "Cacti Rebuild RRD DIR Script 1.0, Copyright 2007 - The Cacti Group\n\n";
        print "usage: rebuild_rrd_dir.php [-d] [-h] [--help] [-v] [--version]\n\n";
        print "-d            - Display verbose output during execution\n";
        print "-v --version  - Display this help message\n";
        print "-h --help     - Display this help message\n";
}

function debug($message) {
        global $debug;

        if ($debug) {
                print("DEBUG: " . $message . "\n");
        }
}


?>


Quote:
RRDTool Command:

/usr/bin/rrdtool graph - \
--imgformat=PNG \
--start=-86400 \
--end=-300 \
--title="localhost - Memory Usage" \
--rigid \
--base=1000 \
--height=120 \
--width=500 \
--alt-autoscale-max \
--lower-limit=0 \
--vertical-label="kilobytes" \
--slope-mode \
--font TITLE:12: \
--font AXIS:8: \
--font LEGEND:10: \
--font UNIT:8: \
DEF:a="/var/www/html/cacti/rra/2/173/59.rrd":mem_buffers:AVERAGE \
DEF:b="/var/www/html/cacti/rra/2/174/60.rrd":mem_swap:AVERAGE \
CDEF:cdefa=a,1024,* \
CDEF:cdefe=b,1024,* \
AREA:cdefa#FF4105:"Free" \
GPRINT:cdefa:LAST:"Current\:%8.2lf %s" \
GPRINT:cdefa:AVERAGE:"Average\:%8.2lf %s" \
GPRINT:cdefa:MAX:"Maximum\:%8.2lf %s\n" \
AREA:cdefe#FFC73B:"Swap":STACK \
GPRINT:cdefe:LAST:"Current\:%8.2lf %s" \
GPRINT:cdefe:AVERAGE:"Average\:%8.2lf %s" \
GPRINT:cdefe:MAX:"Maximum\:%8.2lf %s"
RRDTool Says:

OK


Well, if RRDTools says so: it must be so...
Back to top
oxo-oxo
Cacti User


Joined: 30 Aug 2007
Posts: 113
Location: Silkeborg, Denmark

PostPosted: Tue Sep 11, 2007 2:49 am    Post subject: Reply with quote

From "The Road Map" http://www.cacti.net/roadmap.php ( Last updated: 2007-09-09 )

Cacti 0.8.8
Release end of 1st Quarter 2008

Major Features

Structured host directories

So it must be coming ....
Back to top
Howie
Cacti Guru User


Joined: 16 Sep 2004
Posts: 2248
Location: United Kingdom

PostPosted: Wed Nov 21, 2007 3:58 pm    Post subject: Reply with quote

Just FYI - you can skip the path separator platform checks by using the constant that PHP itself defines: DIRECTORY_SEPARATOR

This is interesting stuff - especially the multiple poller possibilities. I don't have any use for it myself, but it does look interesting!
Back to top
rony
Developer/Forum Admin


Joined: 17 Nov 2003
Posts: 5469
Location: Wisconsin, USA

PostPosted: Wed Nov 21, 2007 4:01 pm    Post subject: Reply with quote

It's coming, been a long time waiting for it.
Back to top
TheWitness
Developer


Joined: 14 May 2002
Posts: 9736
Location: MI, USA

PostPosted: Thu Nov 22, 2007 8:34 am    Post subject: Reply with quote

Both Boost and Structured RRD paths are planned for 0.8.8. So, yes, coming.

TheWitness
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Cacti Forum Index -> Help: Unstable Development Versions All times are GMT - 5 Hours
Goto page 1, 2  Next
Page 1 of 2

 



Powered by phpBB © 2001, 2005 phpBB Group