From 9ea70df20335f4e4a34884a38e34e73a2cb643c8 Mon Sep 17 00:00:00 2001 From: hickert Date: Fri, 30 Jul 2010 14:13:30 +0000 Subject: [PATCH] First - But not finished commit of stats plugin git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19297 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-core/include/class_config.inc | 10 +++ gosa-core/include/class_plugin.inc | 9 +++ gosa-core/include/class_stats.inc | 106 +++++++++++++++++++++++++++++ 3 files changed, 125 insertions(+) create mode 100644 gosa-core/include/class_stats.inc diff --git a/gosa-core/include/class_config.inc b/gosa-core/include/class_config.inc index 7001880bf..4480396be 100644 --- a/gosa-core/include/class_config.inc +++ b/gosa-core/include/class_config.inc @@ -64,6 +64,8 @@ class config { var $filename = ""; var $last_modified = 0; + var $gosaUUID = ""; + private $jsonRPChandle = NULL; public $configRegistry = NULL; @@ -79,6 +81,8 @@ class config { $this->parser = xml_parser_create(); $this->basedir= $basedir; + $this->gosaUUID = uniqid(); + xml_set_object($this->parser, $this); xml_set_element_handler($this->parser, "tag_open", "tag_close"); @@ -92,6 +96,12 @@ class config { } + function getGOsaUUID() + { + return($this->gosaUUID); + } + + /*! \brief Check and reload the configuration * * This function checks if the configuration has changed, since it was diff --git a/gosa-core/include/class_plugin.inc b/gosa-core/include/class_plugin.inc index 4660c375c..bdb9c7aca 100644 --- a/gosa-core/include/class_plugin.inc +++ b/gosa-core/include/class_plugin.inc @@ -145,6 +145,10 @@ class plugin */ function plugin (&$config, $dn= NULL, $object= NULL) { + + $this->initTime = microtime(TRUE); + stats::log('plugin', $class = get_class($this), $action = 'open', $amount = 1, $duration = (microtime(TRUE) - $this->initTime)); + /* Configuration is fine, allways */ $this->config= &$config; $this->dn= $dn; @@ -282,6 +286,7 @@ class plugin session::set('LOCK_VARS_USED_REQUEST',array()); pathNavigator::registerPlugin($this); + stats::log('plugin', $class = get_class($this), $action = 'view', $amount = 1, $duration = microtime(TRUE) - $this->initTime); } /*! \brief Removes object from parent @@ -321,6 +326,7 @@ class plugin */ if($this->initially_was_account){ $this->handle_pre_events('remove'); + stats::log('plugin', $class = get_class($this), $action = 'remove', $amount = 1, $duration = (microtime(TRUE) - $this->initTime)); } } @@ -404,8 +410,10 @@ class plugin if($this->is_new){ $this->handle_pre_events('add'); + stats::log('plugin', $class = get_class($this), $action = 'create', $amount = 1, $duration = (microtime(TRUE) - $this->initTime)); }else{ $this->handle_pre_events('modify'); + stats::log('plugin', $class = get_class($this), $action = 'modify', $amount = 1, $duration = (microtime(TRUE) - $this->initTime)); } } @@ -979,6 +987,7 @@ class plugin return(TRUE); } + stats::log('plugin', $class = get_class($this), $action = 'move', $amount = 1, $duration = (microtime(TRUE) - $this->initTime)); /* Try to move the entry instead of copy & delete */ diff --git a/gosa-core/include/class_stats.inc b/gosa-core/include/class_stats.inc new file mode 100644 index 000000000..4076e202f --- /dev/null +++ b/gosa-core/include/class_stats.inc @@ -0,0 +1,106 @@ +getGOsaUUID(); + $amount = sqlite_escape_string($amount); + $duration = sqlite_escape_string($duration); + $clicks = sqlite_escape_string($clicks); + + $res = stats::checkDatabase(); + $TABLE_NAME = 'stats'; + $query = " + INSERT INTO {$TABLE_NAME} + (ACTID, TYPE, PLUGIN, ACTION, UUID, MTIMESTAMP, TIMESTAMP, AMOUNT, DURATION) + VALUES + ('{$clicks}','{$type}','{$plugin}','{$action}','{$uuid}','{$mtimestamp}','{$timestamp}','{$amount}','{$duration}')"; + sqlite_query($query, $res); + } + + static function show() + { + $res = stats::checkDatabase(); + $TABLE_NAME = 'stats'; + $query = "SELECT * FROM {$TABLE_NAME} ORDER BY MTIMESTAMP"; + $query = "SELECT PLUGIN, ACTION, MAX(DURATION) as 'DURATION' FROM {$TABLE_NAME} WHERE ACTION='modify' GROUP BY PLUGIN,ACTION "; + $query = "SELECT * FROM {$TABLE_NAME} ORDER BY MTIMESTAMP"; + $res = sqlite_query($query, $res); + echo "
";
+        foreach(sqlite_fetch_all($res) as $entry){
+            foreach($entry as $key => $str){
+                if(is_numeric($key)) continue;
+                
+                if($key == "DURATION"){
+                    $str = sprintf("%0.4f", $str);
+                    echo str_pad($str,20,' ', STR_PAD_LEFT)."|"; 
+                }else{
+                    echo str_pad($str,20,' ')."|"; 
+                }
+            }
+            echo "\n";
+        }
+        echo "
"; + echo sqlite_error_string($res); + } +} + + +?> -- 2.30.2