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

add top shellcmd plugin

parent f2986e42
Branches
No related tags found
1 merge request!62V2.0
This commit is part of merge request !62. Comments created here will be created in the context of that merge request.
...@@ -139,6 +139,9 @@ return [ ...@@ -139,6 +139,9 @@ return [
'processes'=>[ 'processes'=>[
'enabled'=>1, 'enabled'=>1,
], ],
'top'=>[
'enabled'=>1,
],
], ],
], ],
......
{
"command": "top -b -n 1 | head -20",
"icon": "fa-solid fa-arrow-up-wide-short",
"interval": 5000,
"window-cols": 50,
"window-lines": 30
}
\ No newline at end of file
{
"name": "Top",
"description": "Show top processes",
"author": "Axel Hahn; University of Bern; Institute for Medical education",
"version": "1.0",
"date": "2023-11-23",
"url": "[included]",
"license": "GNU GPL 3.0"
}
<?php
/**
*
* SHELLCMD PLUGIN :: top
*
* ----------------------------------------------------------------------
* 2023-11-23 axel.hahn@unibe.ch
*/
class shellcmd_top {
/**
* @var fallback command line to exectute; command in config.josn has priority
*/
protected $_command="top -b -n 1 | head -20";
/**
* 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){
$aResult['data']=[
'count'=>count($aResult['output'])-1,
];
return $aResult;
}
}
/*
EXAMPLE OUTPUT
...
*/
\ No newline at end of file
/**
*
* @param {array} aData
* @returns
*/
/**
* callback function for ubd: render html code
* @param {array} aData json object
* @returns {string}
*/
function top_render(aData){
var sReturn='';
sReturn='<span style="float: right">'+aData['time']+'</span>'; // +' '+aData['command']+'</span>';
if(aData['data']['count']==0){
sReturn+='No activity<br><br>Command:<br>'
+aData['command'];
} else {
sReturn+='<pre>';
for(var i=0; i<aData['output'].length; i++){
// sReturn+='<div>'+aData['output'][i]+"</div>";
sReturn+=aData['output'][i]+"<br>";
}
sReturn+='</pre>';
}
return sReturn;
}
function top_init(){
oUbdLoad=new ubd(
{
"domid": "divPluginshellcmdtop",
"url": "/deployment/plugins/shellcmd/getdata.php?plugin=top",
"renderer": top_render,
"ttl": 5,
}
);
// oUbdLoad.render('waiting for first data...');
oUbdLoad.update();
}
window.setTimeout("top_init()", 200);
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment