Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Cronlog-viewer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
Cronlog-viewer
Commits
67e8a82f
Commit
67e8a82f
authored
5 years ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
ignore skipentries in timeline; added phpdocs
parent
e7d4e5d2
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
classes/cronlog-renderer.class.php
+16
-4
16 additions, 4 deletions
classes/cronlog-renderer.class.php
classes/cronlog.class.php
+94
-62
94 additions, 62 deletions
classes/cronlog.class.php
with
110 additions
and
66 deletions
classes/cronlog-renderer.class.php
+
16
−
4
View file @
67e8a82f
...
...
@@ -10,12 +10,15 @@ require_once 'cronlog.class.php';
*/
class
cronlogrenderer
extends
cronlog
{
/**
* minimal length for execution time of a job to be rendered in the timeline; value is in seconds
* @var integer
*/
protected
$_iMinTime4Timeline
=
60
;
/**
* show date of last data and last access
* @param type $iLast
* show date of last data and last access
; used in rendering methods to display it on top
* @param type $iLast
timestamp of last log entry
* @return string
*/
protected
function
_renderAccessAndAge
(
$iLast
){
...
...
@@ -249,6 +252,11 @@ class cronlogrenderer extends cronlog{
return
$sHtml
;
}
/**
* get html code for a joblist of the selected server
* it uses the filter for hidden joblog entries (aHidelogs in config)
* @return string
*/
public
function
renderJoblistOfAllServers
(){
$aData
=
array
();
foreach
(
array_keys
(
$this
->
getServers
())
as
$sServer
){
...
...
@@ -283,7 +291,7 @@ class cronlogrenderer extends cronlog{
}
$iGraphCounter
++
;
if
(
!
$aData
){
$aData
=
$this
->
getServerJobHistory
();
$aData
=
$this
->
getServerJobHistory
(
false
);
}
$sDivId
=
'vis-timeline-'
.
$iGraphCounter
;
...
...
@@ -448,6 +456,10 @@ class cronlogrenderer extends cronlog{
return
$sHtml
;
}
/**
* get html code for a select box with all servers
* @return string
*/
public
function
renderServerlist
(
$sSelectedItem
=
false
){
$sHtml
=
''
;
$sHtml
.
=
'<option value="ALL"'
...
...
This diff is collapsed.
Click to expand it.
classes/cronlog.class.php
+
94
−
62
View file @
67e8a82f
...
...
@@ -21,13 +21,20 @@ class cronlog {
protected
$_iExpiredJobsFailAfter
=
60
*
30
;
// in sec
protected
$_aSkipJoblogs
=
array
();
protected
$_aServers
=
false
;
protected
$_aServers
=
array
()
;
protected
$_sActiveServer
=
false
;
protected
$_sFileFilter_serverjoblog
=
'*joblog*.done'
;
protected
$_sFileFilter_serverlog
=
'*.log'
;
// ----------------------------------------------------------------------
// MAIN
// ----------------------------------------------------------------------
/**
* init
* @return boolean
*/
public
function
__construct
()
{
// read config
...
...
@@ -52,7 +59,7 @@ class cronlog {
/**
* get the full path of directory for caching
*
chaching:
get the full path of directory for caching
* @return type
*/
protected
function
_getCacheDir
(){
...
...
@@ -60,7 +67,7 @@ class cronlog {
}
/**
* get full path of a caching item
*
caching:
get full path of a caching item
* @param type $sTaskId
* @return type
*/
...
...
@@ -69,13 +76,18 @@ class cronlog {
}
/**
* get full path to a servers cronjob logdata
*
read logs:
get full path to a servers cronjob logdata
* @return type
*/
protected
function
_getServerlogDir
(){
return
$this
->
_sDataDir
.
'/'
.
$this
->
_sActiveServer
;
}
/**
* caching: get cached data if they exist and aren't expired
* @param string $sTaskId
* @return boolean|array
*/
protected
function
_getCacheData
(
$sTaskId
){
// DISABLE CACHE return false;
$sFile
=
$this
->
_getCacheFile
(
$sTaskId
);
...
...
@@ -90,6 +102,72 @@ class cronlog {
}
return
false
;
}
/**
* read logs: parse a single line in the joblog and return has with all key value items
* @param string $sLine single line in the log
* @return array
*/
protected
function
_parseJoblogLine
(
$sLine
){
$aReturn
=
array
();
// echo "DEBUG $sLine<br>";
// job=dok-kvm-instances:host=kalium:start=1538358001:end=1538358001:exectime=0:ttl=60:rc=0
$sLine
=
str_replace
(
"
\n
"
,
''
,
$sLine
);
$sLine
=
str_replace
(
':'
,
'", "'
,
$sLine
);
$sLine
=
str_replace
(
'='
,
'": "'
,
$sLine
);
$sLine
=
'{"'
.
$sLine
.
'"}'
;
// echo "DEBUG $sLine<br><br>";
$aReturn
=
json_decode
(
$sLine
,
1
);
if
(
!
is_array
(
$aReturn
)){
echo
"not a JSON string<br>"
;
echo
"DEBUG
$sLine
<br><br>"
;
die
();
}
return
$aReturn
;
}
/**
* read logs: parse the whole cronwrapper logfile and return a hash
* @param string $sFile filename with full path
*/
protected
function
_parseLogfile
(
$sFile
)
{
$aReturn
=
array
(
'SCRIPTNAME'
=>
false
,
'SCRIPTTTL'
=>
false
,
'SCRIPTSTARTTIME'
=>
false
,
'SCRIPTLABEL'
=>
false
,
'SCRIPTENDTIME'
=>
false
,
'SCRIPTEXECTIME'
=>
false
,
'SCRIPTRC'
=>
false
,
// 'SCRIPTOUT'=>array(),
);
$fileHandle
=
fopen
(
$sFile
,
"r"
);
while
((
$line
=
fgets
(
$fileHandle
))
!==
false
)
{
// get key ... the part before "="
$sKey
=
trim
(
preg_replace
(
'/=.*/'
,
''
,
$line
));
if
(
$sKey
&&
isset
(
$aReturn
[
$sKey
])){
// add value ... the part behind "="
$aReturn
[
$sKey
]
=
preg_replace
(
'/^([A-Z]*\=)/'
,
''
,
$line
);
}
}
fclose
(
$fileHandle
);
// fetch unit timestamp from date values (they are like "2018-09-30 03:40:05, 1538278805")
$aReturn
[
'SCRIPTSTARTTIME'
]
=
(
int
)
preg_replace
(
'/.*,\ /'
,
''
,
$aReturn
[
'SCRIPTSTARTTIME'
]);
$aReturn
[
'SCRIPTENDTIME'
]
=
(
int
)
preg_replace
(
'/.*,\ /'
,
''
,
$aReturn
[
'SCRIPTSTARTTIME'
]);
// remove " s" from exec time value
$aReturn
[
'SCRIPTEXECTIME'
]
=
preg_replace
(
'/\ s$/'
,
''
,
$aReturn
[
'SCRIPTEXECTIME'
]);
return
$aReturn
;
}
/**
* caching: write new data; it returns the success of write operation as bool
* @param string $sTaskId
* @param [any] $data data to store; can be any serializable value
* @return boolean
*/
protected
function
_writeCacheData
(
$sTaskId
,
$data
){
$sFile
=
$this
->
_getCacheFile
(
$sTaskId
);
// echo "WRITE cache $sFile<br>";
...
...
@@ -101,7 +179,7 @@ class cronlog {
// ----------------------------------------------------------------------
/**
* get current server
* get current
ly selected
server
* @return string
*/
public
function
getServer
(){
...
...
@@ -138,32 +216,12 @@ class cronlog {
return
$this
->
_aServers
;
}
/**
*
*/
protected
function
_parseJoblogLine
(
$sLine
){
$aReturn
=
array
();
// echo "DEBUG $sLine<br>";
// job=dok-kvm-instances:host=kalium:start=1538358001:end=1538358001:exectime=0:ttl=60:rc=0
$sLine
=
str_replace
(
"
\n
"
,
''
,
$sLine
);
$sLine
=
str_replace
(
':'
,
'", "'
,
$sLine
);
$sLine
=
str_replace
(
'='
,
'": "'
,
$sLine
);
$sLine
=
'{"'
.
$sLine
.
'"}'
;
// echo "DEBUG $sLine<br><br>";
$aReturn
=
json_decode
(
$sLine
,
1
);
if
(
!
is_array
(
$aReturn
)){
echo
"not a JSON string<br>"
;
echo
"DEBUG
$sLine
<br><br>"
;
die
();
}
return
$aReturn
;
}
/**
* get logs from jobfilea of the current or given server
* @param boolean $bUseSkip hide jobs if their label matches the skip list; default: true
* @return array
*/
public
function
getServerJobHistory
(){
public
function
getServerJobHistory
(
$bUseSkip
=
true
){
$aReturn
=
array
();
$sTaskId
=
__FUNCTION__
.
'-'
.
$this
->
_sActiveServer
;
...
...
@@ -180,7 +238,7 @@ class cronlog {
while
((
$line
=
fgets
(
$fileHandle
))
!==
false
)
{
// send the current file part to the browser
$aData
=
$this
->
_parseJoblogLine
(
$line
);
if
(
array_search
(
$aData
[
'job'
],
$this
->
_aSkipJoblogs
)
===
false
){
if
(
!
$bUseSkip
&&
array_search
(
$aData
[
'job'
],
$this
->
_aSkipJoblogs
)
===
false
){
$aReturn
[
$aData
[
'start'
]]
=
$aData
;
}
}
...
...
@@ -191,39 +249,7 @@ class cronlog {
return
$aReturn
;
}
protected
function
_parseLogfile
(
$sFile
)
{
$aReturn
=
array
(
'SCRIPTNAME'
=>
false
,
'SCRIPTTTL'
=>
false
,
'SCRIPTSTARTTIME'
=>
false
,
'SCRIPTLABEL'
=>
false
,
'SCRIPTENDTIME'
=>
false
,
'SCRIPTEXECTIME'
=>
false
,
'SCRIPTRC'
=>
false
,
// 'SCRIPTOUT'=>array(),
);
$fileHandle
=
fopen
(
$sFile
,
"r"
);
while
((
$line
=
fgets
(
$fileHandle
))
!==
false
)
{
// get key ... the part before "="
$sKey
=
trim
(
preg_replace
(
'/=.*/'
,
''
,
$line
));
if
(
$sKey
&&
isset
(
$aReturn
[
$sKey
])){
// add value ... the part behind "="
$aReturn
[
$sKey
]
=
preg_replace
(
'/^([A-Z]*\=)/'
,
''
,
$line
);
}
}
fclose
(
$fileHandle
);
// fetch unit timestamp from date values (they are like "2018-09-30 03:40:05, 1538278805")
$aReturn
[
'SCRIPTSTARTTIME'
]
=
(
int
)
preg_replace
(
'/.*,\ /'
,
''
,
$aReturn
[
'SCRIPTSTARTTIME'
]);
$aReturn
[
'SCRIPTENDTIME'
]
=
(
int
)
preg_replace
(
'/.*,\ /'
,
''
,
$aReturn
[
'SCRIPTSTARTTIME'
]);
// remove " s" from exec time value
$aReturn
[
'SCRIPTEXECTIME'
]
=
preg_replace
(
'/\ s$/'
,
''
,
$aReturn
[
'SCRIPTEXECTIME'
]);
return
$aReturn
;
}
/**
* get logs from jobfilea of the current or given server
* @return array
...
...
@@ -246,6 +272,12 @@ class cronlog {
// public setter
// ----------------------------------------------------------------------
/**
* set which server is selected
* The given server must exist as directory (that contains its logs)
* @param string $sServer server name
* @return string
*/
public
function
setServer
(
$sServer
){
$this
->
_sActiveServer
=
false
;
if
(
$sServer
===
'ALL'
){
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment