Dashboard: use hooks to create elements

This commit is contained in:
bergware
2023-12-14 03:30:44 +01:00
parent 952f432058
commit 2dcaa4fe77
5 changed files with 13 additions and 27 deletions
+4 -13
View File
@@ -73,6 +73,9 @@ $vdisk = exec("grep -Pom1 '^DOCKER_IMAGE_TYPE=\"\\K[^\"]+' /boot/config/docker.c
$dot = _var($display,'number','.,')[0];
$zfs = count(array_filter(array_column($disks,'fsType'),function($fs){return str_replace('luks:','',$fs??'')=='zfs';}));
chmod("$docroot/webGui/system/VM usage",$libvirtd ? 0755 : 0644);
chmod("$docroot/webGui/system/ZFS cache",$zfs ? 0755 : 0644);
foreach ($disks as $disk) {
switch (_var($disk,'type')) {
case 'Data':
@@ -276,12 +279,6 @@ foreach ($cpus as $pair) {
<i class='ups fa fa-expand'></i>_(Maximum size)_: <?="$memory_maximum $unit"?><?=$low?'*':''?>
<legend>_(Legend)_</legend>
<i class='ups fa fa-circle used'></i>_(Services)_: <span id='used'></span><br>
<?if($libvirtd):?>
<i class='ups fa fa-circle vmsize'></i>_(VM usage)_: <span id='vmsize'></span><br>
<?endif;?>
<?if($zfs):?>
<i class='ups fa fa-circle zfs'></i>_(ZFS cache)_: <span id='zfs'></span><br>
<?endif;?>
<span id='dynamic'></span>
<i class='ups fa fa-circle free'></i>_(Free)_: <span id='free'></span><br>
</div></span>
@@ -1505,12 +1502,6 @@ dashboard.on('message',function(msg,meta) {
$('.var'+k).text(v[1]);
if (k == 0) {
$('#used').text(v[5]);
<?if ($libvirtd):?>
$('#vmsize').text(v[7]);
<?endif;?>
<?if ($zfs):?>
$('#zfs').text(v[9]);
<?endif;?>
var color = setColor(load,<?=$display['critical']?>,<?=$display['warning']?>);
$('.sys0_').text(v[0]);
$('#sys0_').finish().animate({width:v[0]},{step:function(){$('#sys0_').css('overflow','visible').removeClass().addClass(color);}});
@@ -1529,7 +1520,7 @@ dashboard.on('message',function(msg,meta) {
var names = (dynamic[1]||'').split('\r');
// dynamic info from hook scripts
var html = [];
for (var i=0,name; name=names[i]; i++) if (name) html.push("<i class='ups fa fa-circle' style='color:"+colors[i+4]+"'></i>"+name+": "+v[i*2+11]+"<br>");
for (var i=0,name; name=names[i]; i++) if (name) html.push("<i class='ups fa fa-circle' style='color:"+colors[i+2]+"'></i>"+_(name)+": "+v[i*2+7]+"<br>");
$('#dynamic').html(html.join(''));
$('#free').text(v[3]);
+5 -12
View File
@@ -14,7 +14,6 @@
<?
$docroot = '/usr/local/emhttp';
$varroot = '/var/local/emhttp';
$pidfile = '/var/run/libvirt/libvirtd.pid';
require_once "$docroot/webGui/include/Helpers.php";
require_once "$docroot/webGui/include/publish.php";
@@ -26,31 +25,25 @@ require_once "$docroot/webGui/include/Translations.php";
$md5_old = -1;
while (true) {
extract(parse_plugin_cfg('dynamix',true));
unset($memory,$df,$fans,$lsof,$meminfo,$sysinfo);
unset($memory,$df,$fans,$lsof);
exec("awk '/^Mem(Total|Available)/{print $2*1024}' /proc/meminfo",$memory);
exec("df --output=pcent,used /boot /var/log /var/lib/docker 2>/dev/null|awk '(NR>1){print $1,$2*1024}'",$df);
exec("sensors -uA 2>/dev/null|grep -Po 'fan\d_input: \K\d+'",$fans);
$vmsize = file_exists($pidfile) ? exec("virsh domstats --list-active --balloon | awk -F= '/^ *balloon.rss=/{t+=\$2}END{print t*1024}'") : 0;
$zfs = exec("awk '/^size/{print \$3;exit}' /proc/spl/kstat/zfs/arcstats 2>/dev/null") ?: 0;
[$total,$free] = $memory;
$used = $total-$free;
$names = $bytes = [];
$hooks = array_slice(array_filter(glob("/usr/local/emhttp/plugins/*/system/*",GLOB_NOSORT),function($file){return is_executable($file);}),0,8);
$used = $total-$free;
$names = $bytes = $meminfo = $sysinfo = [];
$hooks = array_filter(glob("/usr/local/emhttp/plugins/*/system/*",GLOB_NOSORT),function($file){return is_executable($file);});
foreach ($hooks as $hook) {
$names[] = basename($hook); // name of element
$bytes[] = @intval(exec(escapeshellarg($hook))); // value in bytes of element
}
$services = $used-$vmsize-$zfs-array_sum($bytes);
$services = $used-array_sum($bytes);
$meminfo[] = round(100*$used/$total)."%";
$meminfo[] = my_scale($used,$unit,null,-1,1024)." $unit";
$meminfo[] = round(100*$free/$total);
$meminfo[] = my_scale($free,$unit,null,-1,1024)." $unit";
$meminfo[] = round(100*$services/$total);
$meminfo[] = my_scale($services,$unit,null,-1,1024)." $unit";
$meminfo[] = round(100*$vmsize/$total);
$meminfo[] = my_scale($vmsize,$unit,null,-1,1024)." $unit";
$meminfo[] = round(100*$zfs/$total);
$meminfo[] = my_scale($zfs,$unit,null,-1,1024)." $unit";
foreach ($bytes as $byte) {
// parse hook information
$meminfo[] = round(100*$byte/$total);
@@ -74,7 +74,5 @@ div.pie{height:96px;width:96px;border-radius:50%;display:flex;justify-content:ce
div.pie::after{content:'';position:absolute;height:72px;width:72px;border-radius:50%}
div.pie span{z-index:2;font-size:1.6rem;font-weight:bold}
div.more{margin-top:8px}
i.vmsize{color:#d77e0d}
i.zfs{color:#d4ac0d}
.var0,.var1,.var2,.var3{display:none;font-size:1.3rem!important}
legend{font-variant:small-caps;margin:8px 0 4px 0}
+2
View File
@@ -0,0 +1,2 @@
#!/bin/bash
virsh domstats --list-active --balloon 2>/dev/null | awk -F= '/^ *balloon.rss=/{t+=$2}END{print t*1024}'
+2
View File
@@ -0,0 +1,2 @@
#!/bin/bash
awk '/^size/{print $3;exit}' /proc/spl/kstat/zfs/arcstats 2>/dev/null