Skip to content
Snippets Groups Projects

5534 add docker

6 files
+ 324
0
Compare changes
  • Side-by-side
  • Inline

Files

<?php
/**
*
* SHELLCMD PLUGIN :: LOAD
*
* ----------------------------------------------------------------------
* 2022-08-05 axel.hahn@iml.unibe.ch
*/
class shellcmd_load {
/**
* @var command line to exectute
*/
protected $_command='uptime';
/**
* constructor ... returns command
* @return string
*/
public function __constructor(){
return $this->getCommand();
}
/**
* get command
* @return string
*/
public function getCommand(){
return $this->_command;
}
/**
* parse output and extract wanted values in section "data"
* @return array
*/
public function parsedata($aResult){
$aTmp1=array_reverse(explode(',', $aResult['output'][0]));
// print_r($aTmp1);
$aResult['data']=[
'uptime'=>trim($aTmp1[4]),
'users'=>trim(str_replace(' users', '', $aTmp1[3])),
'load'=>trim(preg_replace('/^.*:/', '', $aTmp1[2])),
'load5'=>trim($aTmp1[1]),
'load15'=>trim($aTmp1[0]),
];
return $aResult;
}
}
/*
EXAMPLE OUTPUT
{
"command": "uptime",
"exitcode": 0,
"output": [
" 13:36:54 up 1 day, 7:39, 0 users, load average: 1.18, 1.29, 1.33"
],
"data": {
"uptime": "7:39",
"users": "0",
"load": "1.18",
"load5": "1.29",
"load15": "1.33"
}
}
*/
\ No newline at end of file
Loading