diff --git a/config/config_defaults.php b/config/config_defaults.php index 6c7cd6e3de4f6863b2bb2226cb412a7340cb2041..3c516807ed3ebd143dc59c0da5059c10d9f7b1dc 100644 --- a/config/config_defaults.php +++ b/config/config_defaults.php @@ -139,6 +139,9 @@ return [ 'processes'=>[ 'enabled'=>1, ], + 'top'=>[ + 'enabled'=>1, + ], ], ], diff --git a/public_html/deployment/plugins/shellcmd/top/config.json b/public_html/deployment/plugins/shellcmd/top/config.json new file mode 100644 index 0000000000000000000000000000000000000000..9ea4596cb71da96649640a72cd8b2acdf02ea0e9 --- /dev/null +++ b/public_html/deployment/plugins/shellcmd/top/config.json @@ -0,0 +1,7 @@ +{ + "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 diff --git a/public_html/deployment/plugins/shellcmd/top/info.json b/public_html/deployment/plugins/shellcmd/top/info.json new file mode 100644 index 0000000000000000000000000000000000000000..ea2363aacb184bf5a14f6c908bd947463cd4529b --- /dev/null +++ b/public_html/deployment/plugins/shellcmd/top/info.json @@ -0,0 +1,11 @@ +{ + "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" +} + diff --git a/public_html/deployment/plugins/shellcmd/top/plugin.php b/public_html/deployment/plugins/shellcmd/top/plugin.php new file mode 100644 index 0000000000000000000000000000000000000000..2b64044c2a45605bd643e5bbfa6c5eee74d23379 --- /dev/null +++ b/public_html/deployment/plugins/shellcmd/top/plugin.php @@ -0,0 +1,47 @@ +<?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 diff --git a/public_html/deployment/plugins/shellcmd/top/render.js b/public_html/deployment/plugins/shellcmd/top/render.js new file mode 100644 index 0000000000000000000000000000000000000000..9b0147843bf29ec2bc7f8026a9d449c557447e72 --- /dev/null +++ b/public_html/deployment/plugins/shellcmd/top/render.js @@ -0,0 +1,42 @@ +/** + * + * @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