Dashboard: added dynamic element creation in RAM usage graph

This commit is contained in:
bergware
2023-12-14 02:21:21 +01:00
parent 3e427d2802
commit 952f432058
2 changed files with 38 additions and 18 deletions
+19 -8
View File
@@ -33,18 +33,29 @@ while (true) {
$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;
$services = $used-$vmsize-$zfs;
$meminfo[] = round(100*$used/$total).'%';
$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);
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);
$meminfo[] = round(100*$used/$total)."%";
$meminfo[] = my_scale($used,$unit,null,-1,1024)." $unit";
$meminfo[] = round(100*($free)/$total);
$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[] = 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\0";
$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);
$meminfo[] = my_scale($byte,$unit,null,-1,1024)." $unit";
}
foreach ($df as $data) {
[$pcent,$used] = explode(' ',$data);
$sysinfo[] = $pcent.';'.my_scale($used,$unit,null,-1,1024)." $unit";
@@ -53,7 +64,7 @@ while (true) {
exec("LANG='en_US.UTF8' lsof -Owl /mnt/disk[0-9]* 2>/dev/null|awk '/^shfs/ && \$0!~/\.AppleD(B|ouble)/ && \$5==\"REG\"'|awk -F/ '{print \$4}'",$lsof);
$counts = array_count_values($lsof); $count = [];
foreach ($name as $share) $count[] = $counts[$share] ?? 0;
$echo = implode(";",$meminfo).implode("\0",$sysinfo)."\1".(count($fans)?implode(" RPM\0",$fans).' RPM':'')."\1".implode("\0",$count);
$echo = implode(";",$meminfo)."\n".implode("\r",$names)."\0".implode("\0",$sysinfo)."\1".(count($fans)?implode(" RPM\0",$fans).' RPM':'')."\1".implode("\0",$count);
$md5_new = md5($echo,true);
if ($md5_new !== $md5_old) {
publish('update1', $echo);