From: hickert Date: Wed, 18 Aug 2010 15:28:09 +0000 (+0000) Subject: Updated stats handling fixed float problem X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=fe84544218e0a89c31cc5cd4e0d7a94dbc477604;p=gosa.git Updated stats handling fixed float problem git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19409 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-core/include/class_stats.inc b/gosa-core/include/class_stats.inc index 282fc2c45..d5e56ede0 100644 --- a/gosa-core/include/class_stats.inc +++ b/gosa-core/include/class_stats.inc @@ -2,7 +2,7 @@ class stats { - + static protected $lastCpuLoad = ""; static protected $lastCpuLoadTimestamp = 0; @@ -73,7 +73,7 @@ class stats if(!is_writeable($path) && !is_writeable(dirname($tableFile))){ return(NULL); } - + // Try to create database, if it exists just open it. $handle = sqlite_open($tableFile, 0666, $error); if($handle){ @@ -224,23 +224,20 @@ class stats $overallRenderTimer = microtime(TRUE); } - $duration = stats::prepareFloatForWriting($duration); - $renderTime = stats::prepareFloatForWriting($renderTime); - // Prepare values to be useable within a database $uuid = $config->getGOsaUUID(); $type = sqlite_escape_string($type); $plugin = sqlite_escape_string($plugin); $action = sqlite_escape_string($action); $timestamp = time(); - $mtimestamp = microtime(TRUE); + $mtimestamp = number_format(microtime(TRUE), 4,'.',''); $amount = sqlite_escape_string($amount); - $duration = sqlite_escape_string($duration); - $renderTime = sqlite_escape_string($renderTime); + $duration = sqlite_escape_string(number_format($duration, 4,'.','')); + $renderTime = sqlite_escape_string(number_format($renderTime, 4,'.','')); $info = sqlite_escape_string($info); $clicks = sqlite_escape_string($clicks); $memory_usage = sqlite_escape_string(stats::get_memory_usage()); - $cpu_load = sqlite_escape_string(sprintf("%0.6f",stats::get_cpu_load())); + $cpu_load = sqlite_escape_string(number_format(stats::get_cpu_load(),4,'.','')); // Clean up category, which usally comes from acl_category and may still contain // some special chars like / @@ -249,21 +246,21 @@ class stats $tmp[] = trim($cat, '\/,; '); } $category = sqlite_escape_string(implode($tmp, ', ')); - + // Create insert statement. $TABLE_NAME = stats::$tableName; $query = " INSERT INTO {$TABLE_NAME} - (ACTID, TYPE, PLUGIN, CATEGORY, ACTION, UUID, MTIMESTAMP, TIMESTAMP, - AMOUNT, DURATION, RENDER_TIME, MEMORY_USAGE, CPU_LOAD, INFO) + (ACTID, TYPE, PLUGIN, CATEGORY, ACTION, UUID, MTIMESTAMP, TIMESTAMP, + AMOUNT, DURATION, RENDER_TIME, MEMORY_USAGE, CPU_LOAD, INFO) VALUES - ('{$clicks}','{$type}','{$plugin}','{$category}','{$action}','{$uuid}', - '{$mtimestamp}','{$timestamp}','{$amount}','{$duration}','{$renderTime}', - '{$memory_usage}','{$cpu_load}','{$info}')"; + ('{$clicks}','{$type}','{$plugin}','{$category}','{$action}','{$uuid}', + '{$mtimestamp}','{$timestamp}','{$amount}','{$duration}','{$renderTime}', + '{$memory_usage}','{$cpu_load}','{$info}')"; sqlite_query($query, $res); } - + /*! \brief Closes all sqlite handles opened by this class */ static function closeHandles() @@ -274,8 +271,8 @@ class stats } } } - - + + /*! \brief This method returns all entries of the GOsa-stats table. * You can limit the result by setting the from/to parameter (timestamp). * @param int from The timestamp to start the result from. @@ -295,7 +292,7 @@ class stats return($ret); } - + static function removeStatsFile($filename) { // Get statsFile property @@ -310,7 +307,7 @@ class stats if(empty($path)){ return(NULL); } - + // Check if file exists and then remove it if(isset(stats::$lastHandle[$filename]) && is_resource(stats::$lastHandle[$filename])){ sqlite_close(stats::$lastHandle[$filename]); @@ -318,405 +315,6 @@ class stats if(file_exists($path.'/'.$filename)){ unlink($path.'/'.$filename); } - } - - - /*! \brief This is just a dummy output/debug method - * It directly prints some stats and table infos on the screen. - */ - static function show() - { - $res = stats::getDatabaseHandle(); -# stats::dropTable($res); - if(!$res) return; - - $TABLE_NAME = stats::$tableName; - $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 30"; - $query = "SELECT * FROM {$TABLE_NAME} WHERE plugin != 'LDAP' ORDER BY ID DESC LIMIT 30"; - $ret = sqlite_query($query, $res); - echo "
";
-
-        $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" || $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,$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, UUID 
-            FROM {$TABLE_NAME}
-            WHERE plugin != 'LDAP' 
-            GROUP BY PLUGIN, UUID 
-            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, UUID 
-            FROM {$TABLE_NAME}
-            WHERE   TYPE = 'plugin'
-             AND    PLUGIN != 'LDAP'
-             AND    ACTION = 'open'
-            GROUP BY ACTION,PLUGIN, UUID
-            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 "Time per session\n";
-        echo "------ \n";
-
-        $query = "
-            SELECT SUM(DURATION) as DUR, UUID
-            FROM {$TABLE_NAME}
-            GROUP BY UUID
-            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 "Most used password hashes\n";
-        echo "------ \n";
-
-        $query = "
-            SELECT DISTINCT(INFO), COUNT(INFO) as CNT
-            FROM {$TABLE_NAME}
-            WHERE ACTION = 'change_password'
-            GROUP BY INFO
-            ORDER BY INFO 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 "Actions at all\n";
-        echo "------ \n";
-
-        $query = "
-            SELECT DISTINCT(ACTION), COUNT(ACTION)  AS CNT
-            FROM {$TABLE_NAME}
-            GROUP BY ACTION
-            ORDER BY CNT 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 action\n";
-        echo "------ \n";
-
-        $query = "
-            SELECT DISTINCT(ACTION), SUM(DURATION) AS DUR
-            FROM {$TABLE_NAME}
-            GROUP BY ACTION
-            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 "Average time per action\n";
-        echo "------ \n";
-
-        $query = "
-            SELECT DISTINCT(ACTION), AVG(DURATION) AS DUR
-            FROM {$TABLE_NAME}
-            GROUP BY ACTION
-            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 "Rendertime per plugin\n";
-        echo "------ \n";
-
-        $query = "
-            SELECT PLUGIN, RENDER_TIME AS RM
-            FROM {$TABLE_NAME}
-            GROUP BY PLUGIN
-            ORDER BY RM 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 "
"; - } - - - /*! \brief Somehow sqlite can not work with float values when it comes to AVG() SUM(). - * We use this methods to convert float values to int and vice versa. - * The database will then contain 'int' intead of 'float'. - * prepareFloatForReading -> Used for reading 'float' values. - * prepareFloatForWriting -> Used for writing 'float' values. - * @param float The 'float' value to convert. - * @return int The converted float value. - */ - static function prepareFloatForWriting($float) - { - return(floor($float * 1000)); - } - - - - /*! \brief Somehow sqlite can not work with float values when it comes to AVG() SUM(). - * We use this methods to convert float values to int and vice versa. - * The database will then contain 'int' intead of 'float'. - * prepareFloatForWriting -> Used for writing 'float' values. - * @param float The 'int' value read from the table. - * @return int The converted int value. - */ - static function prepareFloatForReading($int) - { - return($int / 1000); } }