Files
webgui/emhttp/plugins/dynamix/nchan/update_1
2023-12-10 06:40:47 +01:00

63 lines
2.6 KiB
PHP
Executable File

#!/usr/bin/php -q
<?PHP
/* Copyright 2005-2023, Lime Technology
* Copyright 2012-2023, Bergware International.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*/
?>
<?
$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";
// add translations
$_SERVER['REQUEST_URI'] = 'main';
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);
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;
$services = $used-$vmsize-$zfs;
$meminfo[] = round(100*$used/$total)."%";
$meminfo[] = my_scale($used,$unit,null,-1,1024)." $unit";
$meminfo[] = round(100*$services/$total)."%";
$meminfo[] = round(100*($used-$zfs)/$total)."%";
$meminfo[] = my_scale($services,$unit,null,-1,1024)." $unit";
$meminfo[] = my_scale($vmsize,$unit,null,-1,1024)." $unit";
$meminfo[] = my_scale($zfs,$unit,null,-1,1024)." $unit";
$meminfo[] = my_scale($free,$unit,null,-1,1024)." $unit\0";
foreach ($df as $data) {
[$pcent,$used] = explode(' ',$data);
$sysinfo[] = $pcent.';'.my_scale($used,$unit,null,-1,1024)." $unit";
}
$name = array_keys((array)parse_ini_file("$varroot/shares.ini"));
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);
$md5_new = md5($echo,true);
if ($md5_new !== $md5_old) {
publish('update1', $echo);
$md5_old = $md5_new;
}
sleep(5);
}
?>