Skip to content
Snippets Groups Projects
Commit bfffe384 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

limit history table to 1000 newest entries

parent a5905d7a
No related branches found
No related tags found
1 merge request!18OP#7365 PHP-8.1 - Upgrade - cronlog Viewer (monitors.ascii)https://projects.iml.unibe.ch/work_packages/7365
...@@ -44,6 +44,13 @@ class cronlogrenderer extends cronlog ...@@ -44,6 +44,13 @@ class cronlogrenderer extends cronlog
*/ */
protected int $_iMinTime4Timeline = 60; 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 * 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 * @param integer $iLast unix timestamp of last log entry
...@@ -55,9 +62,10 @@ class cronlogrenderer extends cronlog ...@@ -55,9 +62,10 @@ class cronlogrenderer extends cronlog
return ''; return '';
} }
$iAge = round((date('U') - $iLast) / 60); $iAge = round((date('U') - $iLast) / 60);
$sAge = ($iAge > 60*24 ? '<span class="message-error">'.$iAge.'</span>' : $iAge);
return '<div class="accessandage">' return '<div class="accessandage">'
. sprintf($this->t("request-time"), date("Y-m-d H:i:s")) . '<br>' . 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)
. '</div>' . '</div>'
; ;
} }
...@@ -365,12 +373,25 @@ class cronlogrenderer extends cronlog ...@@ -365,12 +373,25 @@ class cronlogrenderer extends cronlog
$aData = $this->getServerJobHistory(); $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);
$sTblHead = ''; $sTblHead = '';
$iOK = 0; $iOK = 0;
$iErrors = 0; $iErrors = 0;
$iLast = false; $iLast = false;
$iCounter = 0;
// job=dok-kvm-instances:host=kalium:start=1538358001:end=1538358001:exectime=0:ttl=60:rc=0 // job=dok-kvm-instances:host=kalium:start=1538358001:end=1538358001:exectime=0:ttl=60:rc=0
foreach ($aData as $aEntry) { foreach ($aData as $aEntry) {
$iCounter++;
if($iCounter>$this->_iHistoryLimit) {
break;
}
if (!$sTblHead) { if (!$sTblHead) {
foreach ([ foreach ([
$this->t("col-starting-time"), $this->t("col-starting-time"),
......
...@@ -39,15 +39,34 @@ class cronlog ...@@ -39,15 +39,34 @@ class cronlog
{ {
/**
* Data dir with subdirs per host and its cronjob logs
* @var string
*/
protected string $_sDataDir = "__APPDIR__/data"; protected string $_sDataDir = "__APPDIR__/data";
/**
* TTL for cached data
* @var int
*/
protected int $_iTtlCache = 60; // in sec protected int $_iTtlCache = 60; // in sec
/** /**
* when show an error for expired jobs (latency to execute job and sync logs) * When show an error for expired jobs (keep in mind the latency to execute job and sync logs)
* @var integer * @var integer
*/ */
protected int $_iExpiredJobsFailAfter = 60 * 30; // in sec protected int $_iExpiredJobsFailAfter = 60 * 30; // in sec
/**
* Minimal TTL for a cronjob
* @var int
*/
protected int $_iMinTtl = 0; // in sec protected int $_iMinTtl = 0; // in sec
/**
* List of cronjobs to hide in the web view
* @var array
*/
protected array $_aSkipJoblogs = []; protected array $_aSkipJoblogs = [];
protected array $_aInstances = []; protected array $_aInstances = [];
...@@ -131,9 +150,9 @@ class cronlog ...@@ -131,9 +150,9 @@ class cronlog
/** /**
* Caching: get cached data if they exist and aren't expired * Caching: get cached data if they exist and aren't expired
* @param string $sTaskId Name of the task * @param string $sTaskId Name of the task
* @return mixed boolean|array * @return mixed string|array
*/ */
protected function _getCacheData(string $sTaskId): string protected function _getCacheData(string $sTaskId): string|array
{ {
// DISABLE CACHE return false; // DISABLE CACHE return false;
$sFile = $this->_getCacheFile($sTaskId); $sFile = $this->_getCacheFile($sTaskId);
...@@ -292,7 +311,7 @@ class cronlog ...@@ -292,7 +311,7 @@ class cronlog
// send the current file part to the browser // send the current file part to the browser
$aData = $this->_parseJoblogLine($line); $aData = $this->_parseJoblogLine($line);
if (!$bUseSkip || array_search($aData['job'], $this->_aSkipJoblogs) === false) { if (!$bUseSkip || array_search($aData['job'], $this->_aSkipJoblogs) === false) {
$aReturn[$aData['start']] = $aData; $aReturn[$aData['start'].'__'.$aData['host'].'__'.$aData['job']] = $aData;
} }
} }
fclose($fileHandle); fclose($fileHandle);
......
...@@ -26,7 +26,7 @@ return [ ...@@ -26,7 +26,7 @@ return [
"history" => "History", "history" => "History",
"history-head" => "History", "history-head" => "History",
"history-hint" => "Von den gestarteten Cronjobs werden die Ausf&uuml;hrungszeiten und deren Exitcode f&uuml;r 6 Tage aufgehoben.", "history-hint" => "Von den gestarteten Cronjobs werden die Ausf&uuml;hrungszeiten und deren Exitcode f&uuml;r mehrere Tage aufgehoben.",
"timeline" => "Timeline", "timeline" => "Timeline",
"timeline-head" => "Graph mit Timeline", "timeline-head" => "Graph mit Timeline",
......
...@@ -26,7 +26,7 @@ return [ ...@@ -26,7 +26,7 @@ return [
"history" => "History", "history" => "History",
"history-head" => "History", "history-head" => "History",
"history-hint" => "The cronwrapper keeps data for 6 days. For each executed cronjob you can see execution times and exitcode.", "history-hint" => "The cronwrapper keeps execution history data for multiples days. For each executed cronjob you can see execution times and exitcode.",
"timeline" => "Timeline", "timeline" => "Timeline",
"timeline-head" => "Graph with timeline", "timeline-head" => "Graph with timeline",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment