From 9060c10b4370d226405ed25c18280c628262534b Mon Sep 17 00:00:00 2001 From: gggeek Date: Thu, 2 Jul 2020 21:34:33 +0000 Subject: [PATCH] improvements to logs view; reduce warnings --- classes/ezlogsgrapher.php | 41 +++++++++++-------- classes/ezsysinfoclustermanager.php | 6 +-- classes/ezsysinfomodule.php | 2 +- design/standard/templates/sysinfo/logview.tpl | 2 +- .../templates/sysinfo/policiesreport.tpl | 4 +- doc/changelogs/CHANGELOG-0.9.15-to-0.9.16 | 7 ++++ modules/sysinfo/genericview.php | 3 +- modules/sysinfo/logview.php | 1 - modules/sysinfo/storagechurn.php | 4 +- 9 files changed, 42 insertions(+), 28 deletions(-) create mode 100644 doc/changelogs/CHANGELOG-0.9.15-to-0.9.16 diff --git a/classes/ezlogsgrapher.php b/classes/ezlogsgrapher.php index d24e7d9..33ed5ce 100644 --- a/classes/ezlogsgrapher.php +++ b/classes/ezlogsgrapher.php @@ -17,14 +17,19 @@ function calcChurnLabel( $pos, $step ) class ezLogsGrapher { - static $lastError = ''; + // assume that ezlog format could have been slightly tweaked + static $ezLogRegexp = '/^\[ ?([A-Za-z0-9:\- ]+) ?\] \[([0-9.]*)\] (.*)/'; + static $storageLogRegexp = '/^\[ ?([A-Za-z0-9:\- ]+) ?\] \[(.*)\]$/'; + static $exclude_regexp = '#\] Timing Point: #'; /** * Parses an eZ log file, returns a (nested) array with one value per log message - * @return array + * @param string $logfile + * @return array[] + * @todo add support for storage log format */ - static function splitLog( $logfile, $exclude_regexp='#\] Timing Point: #' ) + static function splitLog( $logfile ) { $file = file( $logfile ); $data = array(); @@ -35,7 +40,7 @@ static function splitLog( $logfile, $exclude_regexp='#\] Timing Point: #' ) $label = ''; foreach ( $file as $line ) { - if ( preg_match( '/^\[ ([A-Za-z0-9: ]+) \] \[([0-9.]*)\] (.*)/', $line, $matches ) ) + if ( preg_match( self::$ezLogRegexp, $line, $matches ) ) { if ( $time > 0 ) { @@ -43,13 +48,13 @@ static function splitLog( $logfile, $exclude_regexp='#\] Timing Point: #' ) } $time = 0; $content = ''; - if ( !preg_match( $exclude_regexp, $line ) ) + if ( !preg_match( self::$exclude_regexp, $line ) ) { - $date = $matches[1]; + $date = trim( $matches[1] ); /// @todo test if $time > 0 else log error $time = strtotime( $date ); $ip = $matches[2]; - $label = $matches[3]; + $label = ( trim( $matches[3] ) != ':' ? $matches[3] : '' ); } } else @@ -65,11 +70,14 @@ static function splitLog( $logfile, $exclude_regexp='#\] Timing Point: #' ) } /** - * Returns an array where indexes are timestamps, and values are the number of log events found - * @param $scale the time interval used to average (default: 1 minute) - * @return array - */ - static function parseLog( $logfile, $scale=60, $exclude_regexp='#\] Timing Point: #' ) + * Returns an array where indexes are timestamps, and values are the number of log events found + * @param string $logfile + * @param int $scale the time interval used to average (default: 1 minute) + * @param bool $isStorageLog + * @return array + * @todo rename, this is an histogram generator + */ + static function parseLog( $logfile, $scale = 60, $isStorageLog = false ) { if ( !file_exists( $logfile ) ) { @@ -79,11 +87,12 @@ static function parseLog( $logfile, $scale=60, $exclude_regexp='#\] Timing Point $data = array(); foreach ( $file as $line ) { - if ( strlen( $line ) > 22 && substr( $line, 0, 2 ) == '[ ' && substr( $line, 22, 2) == ' ]' ) + /// @todo verify is this is correct - are date strings long 19 or 20 chars ? Also: move to a regexp... + if ( preg_match( ( $isStorageLog ? self::$storageLogRegexp : self::$ezLogRegexp ), $line, $matches ) ) { - if ( !preg_match( $exclude_regexp, $line ) ) + if ( !preg_match( self::$exclude_regexp, $line ) ) { - $time = strtotime( substr( $line, 2, 20 ) ); + $time = strtotime( $matches[1] ); if ( $time > 0 ) { @@ -142,7 +151,6 @@ static function graph( $data, $dataname, $scale = 60 ) $graph->xAxis->min = $min - ( $scale / 2 ); $graph->xAxis->max = $max + ( $scale / 2 ); $graph->xAxis->labelCallback = 'calcChurnLabel'; - $graph->data[$dataname] = new ezcGraphArrayDataSet( $data ); $graph->driver = new ezcGraphGdDriver2(); $graph->driver->options->imageFormat = IMG_JPEG; // pick a font that is delivered along with ezp @@ -150,6 +158,7 @@ static function graph( $data, $dataname, $scale = 60 ) try { + $graph->data[$dataname] = new ezcGraphArrayDataSet( $data ); $ok = ob_start(); $graph->render( 600, 400, 'php://stdout' ); $content = ob_get_clean(); diff --git a/classes/ezsysinfoclustermanager.php b/classes/ezsysinfoclustermanager.php index f0ea948..4387d3e 100644 --- a/classes/ezsysinfoclustermanager.php +++ b/classes/ezsysinfoclustermanager.php @@ -58,7 +58,7 @@ static public function clusterFileStorageDir() return null; } - static public function clusterDataRetrievalMode() + /*static public function clusterDataRetrievalMode() { $ini = eZINI::instance( 'sysinfo.ini' ); switch( $ini->variable( 'ClusterSettings', 'DataRetrieval' ) ) @@ -68,7 +68,7 @@ static public function clusterDataRetrievalMode() default: return self::RETRIEVAL_MODE_BACKEND; } - } + }*/ /** * The list of nodes in the cluster, as per configuration. @@ -275,4 +275,4 @@ static public function verifyAuthToken( $viewName, $seed ) } return false; } -} \ No newline at end of file +} diff --git a/classes/ezsysinfomodule.php b/classes/ezsysinfomodule.php index ae516f3..2fb4185 100644 --- a/classes/ezsysinfomodule.php +++ b/classes/ezsysinfomodule.php @@ -93,7 +93,7 @@ static function viewDescription( $viewName ) { if ( array_key_exists( $viewName, $views ) ) { - return isset( $views[$viewName]['description'] ) ? $views[$viewName]['description'] : $views[$viewName]; + return isset( $views[$viewName]['description'] ) ? $views[$viewName]['description'] : $views[$viewName]['name']; } } return ''; diff --git a/design/standard/templates/sysinfo/logview.tpl b/design/standard/templates/sysinfo/logview.tpl index 3c4131b..383c202 100644 --- a/design/standard/templates/sysinfo/logview.tpl +++ b/design/standard/templates/sysinfo/logview.tpl @@ -6,7 +6,7 @@

{$title|wash()}

-{* DESIGN: Mainline *}
{$description|wash}
+{* DESIGN: Mainline *}{*
{$description|wash}
*} {'RAW version'|i18n( 'SysInfo')} diff --git a/design/standard/templates/sysinfo/policiesreport.tpl b/design/standard/templates/sysinfo/policiesreport.tpl index a810584..9012f57 100644 --- a/design/standard/templates/sysinfo/policiesreport.tpl +++ b/design/standard/templates/sysinfo/policiesreport.tpl @@ -70,9 +70,7 @@ $limit_node=fetch('content','node', hash('node_id', $limit_location_array[$limit_location_array|count()|sub(2)] )) }{$user.limit_ident|wash}: "{$limit_node.name|wash}" ({$user.limit_value|wash}){else }{set $limit_section=fetch( 'section', 'object', hash( 'section_id', $user.limit_value ) ) - }{$user.limit_ident|wash}: "{$limit_section.name|wash}" ({$user.limit_value|wash}){/if - }{/if - } + }{$user.limit_ident|wash}: "{$limit_section.name|wash}" ({$user.limit_value|wash}){/if}{/if} {set $i = $i|inc()} {/foreach} diff --git a/doc/changelogs/CHANGELOG-0.9.15-to-0.9.16 b/doc/changelogs/CHANGELOG-0.9.15-to-0.9.16 new file mode 100644 index 0000000..1e17fd9 --- /dev/null +++ b/doc/changelogs/CHANGELOG-0.9.15-to-0.9.16 @@ -0,0 +1,7 @@ +Changes from 0.9.15 to 0.9.16 - released xxx-yyy + +Fixed: in storage churn page, avoid exception if there is no data available + +Improved: made the log-parsing algorithms for logs stats and graphs more resilient + +Improved: generate less warnings in ez logs diff --git a/modules/sysinfo/genericview.php b/modules/sysinfo/genericview.php index 73d0cb2..5a89c5d 100644 --- a/modules/sysinfo/genericview.php +++ b/modules/sysinfo/genericview.php @@ -10,7 +10,8 @@ * @todo use a 3-level path, with the name of the group as 2nd element ? */ -/// @var eZModule $module +/** @var array $Params */ +/** @var eZModule $module */ $module = $Params['Module']; $view = $module->currentView(); diff --git a/modules/sysinfo/logview.php b/modules/sysinfo/logview.php index 061b9b5..61d3e91 100644 --- a/modules/sysinfo/logview.php +++ b/modules/sysinfo/logview.php @@ -61,7 +61,6 @@ if ( file_exists( $archivelog ) ) { $data = array_merge( $data, ezLogsGrapher::splitLog( $archivelog ) ); - //var_dump( $archivelog ); } } diff --git a/modules/sysinfo/storagechurn.php b/modules/sysinfo/storagechurn.php index 36bbe1b..61d4d3d 100644 --- a/modules/sysinfo/storagechurn.php +++ b/modules/sysinfo/storagechurn.php @@ -24,7 +24,7 @@ /// @todo return a 404 error? } - $data = ezLogsGrapher::asum( ezLogsGrapher::parseLog( $logfile, $scale ), ezLogsGrapher::parseLog( $logfile2, $scale ) ); + $data = ezLogsGrapher::asum( ezLogsGrapher::parseLog( $logfile, $scale, true ), ezLogsGrapher::parseLog( $logfile2, $scale, true ) ); ksort( $data ); $mtime = @filemtime( $logfile ); @@ -69,7 +69,7 @@ $scalenames = array( 60 => 'minute', 60*60 => 'hour', 60*60*24 => 'day' ); // *** Parse storage.log files *** - $data = ezLogsGrapher::asum( ezLogsGrapher::parseLog( $logfile, $scale ), ezLogsGrapher::parseLog( $logfile2, $scale ) ); + $data = ezLogsGrapher::asum( ezLogsGrapher::parseLog( $logfile, $scale, true ), ezLogsGrapher::parseLog( $logfile2, $scale, true ) ); ksort( $data ); // *** build graph and store it ***