Skip to content

Commit

Permalink
improvements to logs view; reduce warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
gggeek committed Jul 2, 2020
1 parent 6829e20 commit 9060c10
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 28 deletions.
41 changes: 25 additions & 16 deletions classes/ezlogsgrapher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -35,21 +40,21 @@ 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 )
{
$data[] = array( 'date' => $date, 'message' => $content, 'label' => $label, 'source' => $ip, 'timestamp' => $time );
}
$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
Expand All @@ -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 ) )
{
Expand All @@ -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 )
{

Expand Down Expand Up @@ -142,14 +151,14 @@ 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
$graph->options->font = 'design/standard/fonts/arial.ttf';

try
{
$graph->data[$dataname] = new ezcGraphArrayDataSet( $data );
$ok = ob_start();
$graph->render( 600, 400, 'php://stdout' );
$content = ob_get_clean();
Expand Down
6 changes: 3 additions & 3 deletions classes/ezsysinfoclustermanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) )
Expand All @@ -68,7 +68,7 @@ static public function clusterDataRetrievalMode()
default:
return self::RETRIEVAL_MODE_BACKEND;
}
}
}*/

/**
* The list of nodes in the cluster, as per configuration.
Expand Down Expand Up @@ -275,4 +275,4 @@ static public function verifyAuthToken( $viewName, $seed )
}
return false;
}
}
}
2 changes: 1 addition & 1 deletion classes/ezsysinfomodule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '';
Expand Down
2 changes: 1 addition & 1 deletion design/standard/templates/sysinfo/logview.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<h1 class="context-title">{$title|wash()}</h1>

{* DESIGN: Mainline *}<div class="header-mainline">{$description|wash}</div>
{* DESIGN: Mainline *}{*<div class="header-mainline">{$description|wash}</div>*}

<a href={concat('sysinfo/logview/', $logfile, '/(view)/raw')|ezurl()}>{'RAW version'|i18n( 'SysInfo')}</a>

Expand Down
4 changes: 1 addition & 3 deletions design/standard/templates/sysinfo/policiesreport.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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}:&nbsp;"{$limit_node.name|wash}"&nbsp;({$user.limit_value|wash}){else
}{set $limit_section=fetch( 'section', 'object', hash( 'section_id', $user.limit_value ) )
}{$user.limit_ident|wash}:&nbsp;"{$limit_section.name|wash}"&nbsp;({$user.limit_value|wash}){/if
}{/if
}</td>
}{$user.limit_ident|wash}:&nbsp;"{$limit_section.name|wash}"&nbsp;({$user.limit_value|wash}){/if}{/if}</td>
{set $i = $i|inc()}
</tr>
{/foreach}
Expand Down
7 changes: 7 additions & 0 deletions doc/changelogs/CHANGELOG-0.9.15-to-0.9.16
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion modules/sysinfo/genericview.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
1 change: 0 additions & 1 deletion modules/sysinfo/logview.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
if ( file_exists( $archivelog ) )
{
$data = array_merge( $data, ezLogsGrapher::splitLog( $archivelog ) );
//var_dump( $archivelog );
}
}

Expand Down
4 changes: 2 additions & 2 deletions modules/sysinfo/storagechurn.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 ***
Expand Down

0 comments on commit 9060c10

Please sign in to comment.