Skip to content
Snippets Groups Projects

OP#7365 PHP-8.1 - Upgrade - cronlog Viewer (monitors.ascii)https://projects.iml.unibe.ch/work_packages/7365

Merged Hahn Axel (hahn) requested to merge freshup-php into master

Files

+ 41
12
@@ -33,7 +33,7 @@ require_once 'cronlog.class.php';
* @license GNU GPL 3.0
* @author Axel Hahn <axel.hahn@iml.unibe.ch>
*
* 2024-09-20 <axel.hahn@unibe.ch> added type declarations; update php docs
* 2024-10-01 <axel.hahn@unibe.ch> added type declarations; update php docs
*/
class cronlogrenderer extends cronlog
{
@@ -44,6 +44,13 @@ class cronlogrenderer extends cronlog
*/
protected int $_iMinTime4Timeline = 60;
/**
* Max count of entries in history table to prevent freezing of the screen
* when displaying a lot of entries, eg all logs of 100+ servers
* @var int
*/
protected int $_iHistoryLimit = 1000;
/**
* Show date of last data and last access; used in rendering methods to display it on top
* @param integer $iLast unix timestamp of last log entry
@@ -55,9 +62,14 @@ class cronlogrenderer extends cronlog
return '';
}
$iAge = round((date('U') - $iLast) / 60);
$sAge = ($iAge > 60*24 ? '<span class="message-error">'.$iAge.'</span>' : $iAge);
return '<div class="accessandage">'
. sprintf($this->t("request-time"), date("Y-m-d H:i:s")) . '<br>'
. sprintf($this->t("last-entry"), $iAge)
. sprintf($this->t("last-entry"), $sAge)
.($iAge > 60*24
? " <a href=\"?deleteserverlogs=$this->_sActiveServer\" class=\"btn btn-danger\">Delete server</a>"
: ''
)
. '</div>'
;
}
@@ -231,7 +243,7 @@ class cronlogrenderer extends cronlog
// . '<td>'.$aEntry['SCRIPTNAME'].'</td>'
. '<td>' . $aEntry['SCRIPTLABEL'] . '</td>'
. '<td>' . $aEntry['server'] . '</td>'
. '<td'
. '<td align="right"'
. ((int) $aEntry['SCRIPTEXECTIME'] > $this->_iMinTime4Timeline ? ' class="message-warning"' : '')
. '>'
. '<span style="display: none">' . str_pad((int) $aEntry['SCRIPTEXECTIME'], 6, '0', STR_PAD_LEFT) . '</span>'
@@ -239,14 +251,14 @@ class cronlogrenderer extends cronlog
. $iExectime . 's'
. ($iExectime > 100 ? ' (' . round($iExectime / 60) . 'min)' : '')
. '</td>'
. '<td'
. '<td align="right"'
. ($aEntry['SCRIPTTTL'] < $this->_iMinTtl ? ' class="message-warning" title="(using minimal TTL = ' . $this->_iMinTtl . ' min)"' : '')
. '>'
. '<span style="display: none">' . str_pad((int) $aEntry['SCRIPTTTL'], 6, '0', STR_PAD_LEFT) . '</span>'
. $aEntry['SCRIPTTTL']
. $sTtlHr
. '</td>'
. '<td class="' . ($aEntry['SCRIPTRC'] ? ($aEntry['SCRIPTRC'] > 0 ? 'message-error' : 'message-ok') : '') . '">'
. '<td align="right" class="' . ($aEntry['SCRIPTRC'] ? ($aEntry['SCRIPTRC'] > 0 ? 'message-error' : 'message-ok') : '') . '">'
. ($aEntry['SCRIPTRC'] ? $aEntry['SCRIPTRC'] : '⏳')
. '</td>'
. '<td class="' . ($iNextRunWarn < date("U")
@@ -334,7 +346,7 @@ class cronlogrenderer extends cronlog
return '';
}
$sReturn = '';
$sServer = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : false;
$sServer = isset($_SERVER['SERVER_NAME']) ?? false;
$sReturn .= '<li class="nav-item"><a class="nav-link nav-link" data-widget="pushmenu" href="#" role="button"><i class="fas fa-bars"></i></a></li>'
. '<li class="nav-item d-none d-sm-inline-block"><a href="#" class="nav-link">' . $this->t('instances') . ':</a></li>';
@@ -352,7 +364,7 @@ class cronlogrenderer extends cronlog
* @param array $aData result of $oCL->getServerLogs()
* @return string
*/
public function renderJoblist(array $aData = []): string
public function renderHistoryTable(array $aData = []): string
{
$sTaskId = __FUNCTION__ . '-' . $this->_sActiveServer;
$sHtml = $this->_getCacheData($sTaskId);
@@ -365,12 +377,26 @@ class cronlogrenderer extends cronlog
$aData = $this->getServerJobHistory();
}
// sort by starting time - especially before cutting the list
$aTmp=[];
foreach($aData as $sKey => $aEntry) {
$aTmp[$aEntry['start'].'__'.$aEntry['host'].'__'.$aEntry['job']]=$aEntry;
}
krsort($aTmp);
$aData = array_values($aTmp);
// render table
$sTblHead = '';
$iOK = 0;
$iErrors = 0;
$iLast = false;
$iCounter = 0;
// job=dok-kvm-instances:host=kalium:start=1538358001:end=1538358001:exectime=0:ttl=60:rc=0
foreach ($aData as $aEntry) {
$iCounter++;
if($iCounter>$this->_iHistoryLimit) {
break;
}
if (!$sTblHead) {
foreach ([
$this->t("col-starting-time"),
@@ -397,14 +423,14 @@ class cronlogrenderer extends cronlog
// . '<td>'.date("Y-m-d H:i:s", $aEntry['end']).'</td>'
. '<td>' . $aEntry['job'] . '</td>'
. '<td>' . $aEntry['host'] . '</td>'
. '<td'
. '<td align="right"'
. ($aEntry['exectime'] > $this->_iMinTime4Timeline ? ' class="message-warning"' : '')
. '>'
. $aEntry['exectime'] . 's'
. ($aEntry['exectime'] > 100 ? ' (' . round($aEntry['exectime'] / 60) . 'min)' : '')
. '</td>'
. '<td>' . $aEntry['ttl'] . '</td>'
. '<td class="'
. '<td align="right">' . $aEntry['ttl'] . '</td>'
. '<td align="right" class="'
. ($aEntry['rc'] > 0 ? 'message-error' : 'message-ok')
. '">' . $aEntry['rc'] . '</td>'
. '<td>' . ($aEntry['rc'] ? $this->t('status-error') : $this->t('status-ok')) . '</td>'
@@ -461,7 +487,7 @@ class cronlogrenderer extends cronlog
*
* @return string
*/
public function renderJoblistOfAllServers(): string
public function renderHistoryOfAllServers(): string
{
$aData = [];
foreach (array_keys($this->getServers()) as $sServer) {
@@ -469,7 +495,7 @@ class cronlogrenderer extends cronlog
$aData = array_merge($aData, $this->getServerJobHistory());
}
$this->setServer('ALL');
return $this->renderJoblist($aData);
return $this->renderHistoryTable($aData);
}
/**
@@ -570,6 +596,9 @@ class cronlogrenderer extends cronlog
// Create a Timeline
var timeline = new vis.Timeline(container, items, options);
// set focus to newest jobs
// timeline.moveTo("'.date("Y-m-d H:i:s", time()-60*60*24*4).'");
// fix: some timelines do not properly work ... but I make them visible
$(\'#' . $sDivId . ' .vis-timeline\').css(\'visibility\', \'visible\');
Loading