From 34da290273bd0eda5ea52528e0f6a0a832958988 Mon Sep 17 00:00:00 2001 From: hickert Date: Mon, 2 Aug 2010 10:07:17 +0000 Subject: [PATCH] Ensure we either call the plugins constructor or manually set the initTime variable for the new statistics plugin. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19306 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-core/include/class_stats.inc | 294 ++++++++++++++++++++++++++---- 1 file changed, 262 insertions(+), 32 deletions(-) diff --git a/gosa-core/include/class_stats.inc b/gosa-core/include/class_stats.inc index 54420e9d9..e2d64986c 100644 --- a/gosa-core/include/class_stats.inc +++ b/gosa-core/include/class_stats.inc @@ -3,7 +3,8 @@ class stats { - + static protected $last_cpu_load = ""; + static protected $last_cpu_load_stamp = 0; static function checkDatabase() @@ -32,16 +33,19 @@ class stats // Check for table existance $query = " CREATE TABLE {$TABLE_NAME} ( - ID INTEGER PRIMARY KEY, - ACTID INTEGER, - TYPE TEXT, - PLUGIN TEXT, - ACTION TEXT, - UUID TEXT, - TIMESTAMP INTEGER, - MTIMESTAMP INTEGER, - AMOUNT INTEGER, - DURATION INTEGER + ID INTEGER PRIMARY KEY, + ACTID INTEGER, + TYPE TEXT, + PLUGIN TEXT, + CATEGORY TEXT, + ACTION TEXT, + UUID TEXT, + TIMESTAMP INTEGER, + MTIMESTAMP REAL, + DURATION REAL, + AMOUNT INTEGER, + MEMORY_USAGE INTEGER, + CPU_LOAD FLOAT )"; $ret = sqlite_query($query, $res); } @@ -51,54 +55,280 @@ class stats - static function log($type, $plugin, $action, $amount = 1, $duration = 0) + static function log($type, $plugin, $category, $action, $amount = 1, $duration = 0) { global $config; global $clicks; - $type = sqlite_escape_string($type); - $plugin = sqlite_escape_string($plugin); - $action = sqlite_escape_string($action); - $timestamp = time(); - $mtimestamp = microtime(TRUE); - $uuid = $config->getGOsaUUID(); - $amount = sqlite_escape_string($amount); - $duration = sqlite_escape_string($duration); - $clicks = sqlite_escape_string($clicks); + $type = sqlite_escape_string($type); + $plugin = sqlite_escape_string($plugin); + $action = sqlite_escape_string($action); + $timestamp = time(); + $mtimestamp = microtime(TRUE); + $uuid = $config->getGOsaUUID(); + $amount = sqlite_escape_string($amount); + $duration = sqlite_escape_string($duration); + $clicks = sqlite_escape_string($clicks); + $memory_usage = sqlite_escape_string(stats::get_memory_usage()); + $cpu_load = sqlite_escape_string(stats::get_cpu_load()); + + $tmp = array(); + foreach($category as $cat){ + $tmp[] = trim($cat, '\/,; '); + } + $category = sqlite_escape_string(implode($tmp, ', ')); $res = stats::checkDatabase(); $TABLE_NAME = 'stats'; $query = " INSERT INTO {$TABLE_NAME} - (ACTID, TYPE, PLUGIN, ACTION, UUID, MTIMESTAMP, TIMESTAMP, AMOUNT, DURATION) + (ACTID, TYPE, PLUGIN, CATEGORY, ACTION, UUID, MTIMESTAMP, TIMESTAMP, AMOUNT, DURATION, MEMORY_USAGE, CPU_LOAD) VALUES - ('{$clicks}','{$type}','{$plugin}','{$action}','{$uuid}','{$mtimestamp}','{$timestamp}','{$amount}','{$duration}')"; + ('{$clicks}','{$type}','{$plugin}','{$category}','{$action}','{$uuid}', + '{$mtimestamp}','{$timestamp}','{$amount}','{$duration}','{$memory_usage}','{$cpu_load}')"; sqlite_query($query, $res); } + static function get_memory_usage() + { + return(memory_get_usage()); + } + + static function get_cpu_load() + { + $cur = time(); + if(empty(stats::$last_cpu_load) || (($cur - stats::$last_cpu_load_stamp) >=2 )){ + list($one, $five, $ten) =preg_split("/ /",shell_exec('cat /proc/loadavg')); + stats::$last_cpu_load = $one; + stats::$last_cpu_load_stamp = $cur; + } + return(stats::$last_cpu_load); + } + 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 ID DESC LIMIT 20"; - $res = sqlite_query($query, $res); + $query = "SELECT * FROM {$TABLE_NAME} ORDER BY ID DESC LIMIT 30"; + $query = "SELECT * FROM {$TABLE_NAME} WHERE plugin != 'LDAP' ORDER BY ID DESC LIMIT 30"; + $ret = sqlite_query($query, $res); echo "
";
-        foreach(sqlite_fetch_all($res) as $entry){
+
+        $colSize = 16;
+
+        $title = FALSE;
+        foreach(sqlite_fetch_all($ret) as $entry){
+            if(!$title){
+                foreach($entry as $key => $str) {
+                    if(is_numeric($key)) continue;
+                    echo str_pad($key,$colSize,' ')."|";
+                }
+                echo "\n";
+                foreach($entry as $key => $str) {
+                    if(is_numeric($key)) continue;
+                    echo str_pad('',$colSize,'-')."-";
+                }
+                echo "\n";
+                $title = TRUE;
+            }
+ 
             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)."|"; 
+                if($key == "DURATION" || $key == "MTIMESTAMP" || $key == "CPU_LOAD"){
+                    $str = sprintf("%0.4f", preg_replace("/,/",".",$str));
+                    echo str_pad($str,$colSize,' ', STR_PAD_LEFT)."|"; 
                 }else{
-                    echo str_pad($str,20,' ')."|"; 
+                    echo str_pad($str,$colSize,' ')."|"; 
                 }
             }
             echo "\n";
         }
+        echo sqlite_error_string($ret);
+
+        echo "\n------ \n";
+        echo "Time spent per plugin-category \n";
+        echo "------ \n";
+
+        $query = "
+            SELECT SUM(DURATION) AS DUR, CATEGORY 
+            FROM {$TABLE_NAME}
+            WHERE plugin != 'LDAP' 
+            GROUP BY CATEGORY 
+            ORDER BY DUR DESC LIMIT 10";
+        $ret = sqlite_query($query, $res);
+
+        $colSize = 16;
+        $title = FALSE;
+        foreach(sqlite_fetch_all($ret) as $entry){
+            foreach($entry as $key => $str){
+                if(is_numeric($key)) continue;
+                echo str_pad($str,$colSize,' ')."|"; 
+            }
+            echo "\n";
+        }
+
+
+        echo sqlite_error_string($ret);
+
+        echo "\n------ \n";
+        echo "Time spent per plugin \n";
+        echo "------ \n";
+
+        $query = "
+            SELECT SUM(DURATION) AS DUR, PLUGIN 
+            FROM {$TABLE_NAME}
+            WHERE plugin != 'LDAP' 
+            GROUP BY PLUGIN 
+            ORDER BY DUR DESC LIMIT 10";
+        $ret = sqlite_query($query, $res);
+
+        $colSize = 16;
+        $title = FALSE;
+        foreach(sqlite_fetch_all($ret) as $entry){
+            foreach($entry as $key => $str){
+                if(is_numeric($key)) continue;
+                echo str_pad($str,$colSize,' ')."|"; 
+            }
+            echo "\n";
+        }
+        echo sqlite_error_string($ret);
+
+ # * Anzahl von Objekttypen
+ # * Anzahl der Löschungen pro Objekttyp
+ # * Anzahl der Erzeugungen pro Objekttyp
+ # * Anzahl der Bearbeitungen pro Objekttyp
+ # * Anzahl der Verschiebungen pro Objekttyp
+ # * Anzahl der Mehrfachbearbeitungen pro Objekttyp
+ # * Antwortzeiten pro aktion
+ # * Anzahl der Passwortänderungen
+ # * Anzahl der unterschiedlichen Anmeldungen
+
+
+        echo "\n------ \n";
+        echo "Actions done per plugin \n";
+        echo "------ \n";
+
+        $query = "
+            SELECT COUNT(ACTION) as CNT, ACTION, PLUGIN 
+            FROM {$TABLE_NAME}
+            WHERE   TYPE = 'plugin'
+             AND    PLUGIN != 'LDAP'
+            GROUP BY ACTION,PLUGIN 
+            ORDER BY CNT DESC LIMIT 30";
+        $ret = sqlite_query($query, $res);
+
+        $colSize = 16;
+        $title = FALSE;
+        foreach(sqlite_fetch_all($ret) as $entry){
+            foreach($entry as $key => $str){
+                if(is_numeric($key)) continue;
+                echo str_pad($str,$colSize,' ')."|"; 
+            }
+            echo "\n";
+        }
+        echo sqlite_error_string($ret);
+
+        echo "\n------ \n";
+        echo "'create' actions done per plugin  (5 most)\n";
+        echo "------ \n";
+
+        $query = "
+            SELECT COUNT(ACTION) as CNT, ACTION, PLUGIN 
+            FROM {$TABLE_NAME}
+            WHERE   TYPE = 'plugin'
+             AND    PLUGIN != 'LDAP'
+             AND    ACTION = 'create'
+            GROUP BY ACTION,PLUGIN 
+            ORDER BY CNT DESC LIMIT 5";
+        $ret = sqlite_query($query, $res);
+
+        $colSize = 16;
+        $title = FALSE;
+        foreach(sqlite_fetch_all($ret) as $entry){
+            foreach($entry as $key => $str){
+                if(is_numeric($key)) continue;
+                echo str_pad($str,$colSize,' ')."|"; 
+            }
+            echo "\n";
+        }
+        echo sqlite_error_string($ret);
+
+        echo "\n------ \n";
+        echo "'move' actions done per plugin  (5 most)\n";
+        echo "------ \n";
+
+        $query = "
+            SELECT COUNT(ACTION) as CNT, ACTION, PLUGIN 
+            FROM {$TABLE_NAME}
+            WHERE   TYPE = 'plugin'
+             AND    PLUGIN != 'LDAP'
+             AND    ACTION = 'move'
+            GROUP BY ACTION,PLUGIN 
+            ORDER BY CNT DESC LIMIT 5";
+        $ret = sqlite_query($query, $res);
+
+        $colSize = 16;
+        $title = FALSE;
+        foreach(sqlite_fetch_all($ret) as $entry){
+            foreach($entry as $key => $str){
+                if(is_numeric($key)) continue;
+                echo str_pad($str,$colSize,' ')."|"; 
+            }
+            echo "\n";
+        }
+        echo sqlite_error_string($ret);
+
+        echo "\n------ \n";
+        echo "'view' actions done per plugin  (5 most)\n";
+        echo "------ \n";
+
+        $query = "
+            SELECT COUNT(ACTION) as CNT, ACTION, PLUGIN 
+            FROM {$TABLE_NAME}
+            WHERE   TYPE = 'plugin'
+             AND    PLUGIN != 'LDAP'
+             AND    ACTION = 'view'
+            GROUP BY ACTION,PLUGIN 
+            ORDER BY CNT DESC LIMIT 5";
+        $ret = sqlite_query($query, $res);
+
+        $colSize = 16;
+        $title = FALSE;
+        foreach(sqlite_fetch_all($ret) as $entry){
+            foreach($entry as $key => $str){
+                if(is_numeric($key)) continue;
+                echo str_pad($str,$colSize,' ')."|"; 
+            }
+            echo "\n";
+        }
+        echo sqlite_error_string($ret);
+
+        echo "\n------ \n";
+        echo "'open' actions done per plugin  (5 most)\n";
+        echo "------ \n";
+
+        $query = "
+            SELECT COUNT(ACTION) as CNT, ACTION, PLUGIN 
+            FROM {$TABLE_NAME}
+            WHERE   TYPE = 'plugin'
+             AND    PLUGIN != 'LDAP'
+             AND    ACTION = 'open'
+            GROUP BY ACTION,PLUGIN 
+            ORDER BY CNT DESC LIMIT 5";
+        $ret = sqlite_query($query, $res);
+
+        $colSize = 16;
+        $title = FALSE;
+        foreach(sqlite_fetch_all($ret) as $entry){
+            foreach($entry as $key => $str){
+                if(is_numeric($key)) continue;
+                echo str_pad($str,$colSize,' ')."|"; 
+            }
+            echo "\n";
+        }
         echo "
"; - echo sqlite_error_string($res); + echo sqlite_error_string($ret); } } -- 2.30.2