Nchan processes: only publish on changes

This commit is contained in:
bergware
2023-11-28 12:19:09 +01:00
parent 8ef461432f
commit 8fde2e5c3a
7 changed files with 71 additions and 18 deletions
+13 -2
View File
@@ -17,6 +17,8 @@ $varroot = '/var/local/emhttp';
$pool_log = '/var/tmp/pool_log.tmp';
$smartALL = '/boot/config/smart-all.cfg';
$smartONE = '/boot/config/smart-one.cfg';
$md5_old = -1;
$fs_old = -1;
require_once "$docroot/webGui/include/Helpers.php";
require_once "$docroot/webGui/include/publish.php";
@@ -514,8 +516,17 @@ while (true) {
$n++;
$echo[$n] = _var($var,'fsState')=='Stopped' ? 1 : 0;
publish('devices', implode("\0",$echo));
publish('arraymonitor', _var($var,'fsState')=='Started' ? 1 : 0);
$echo = implode("\0",$echo);
$md5_new = md5($echo,true);
if ($md5_new !== $md5_old) {
publish('devices', $echo);
$md5_old = $md5_new;
}
$fs_new = _var($var,'fsState')=='Started' ? 1 : 0;
if ($fs_new !== $fs_old) {
publish('arraymonitor', $fs_new);
$fs_old = $fs_new;
}
sleep(1);
}
?>
+7 -1
View File
@@ -14,11 +14,17 @@
<?
$docroot = '/usr/local/emhttp';
$notify = "$docroot/webGui/scripts/notify";
$md5_old = -1;
require_once "$docroot/webGui/include/publish.php";
while (true) {
publish('notify', shell_exec("$notify get"));
$echo = shell_exec("$notify get");
$md5_new = md5($echo,true);
if ($md5_new !== $md5_old) {
publish('notify', $echo);
$md5_old = $md5_new;
}
sleep(3);
}
?>
+23 -10
View File
@@ -12,12 +12,15 @@
*/
?>
<?
$docroot = '/usr/local/emhttp';
$varroot = '/var/local/emhttp';
$log = '/boot/config/parity-checks.log';
$stamps = '/var/tmp/stamps.ini';
$resync = '/var/tmp/resync.ini';
$timer = time();
$docroot = '/usr/local/emhttp';
$varroot = '/var/local/emhttp';
$log = '/boot/config/parity-checks.log';
$stamps = '/var/tmp/stamps.ini';
$resync = '/var/tmp/resync.ini';
$md5_old = -1;
$spot_old = -1;
$fs_old = -1;
$proc_old = -1;
require_once "$docroot/webGui/include/Helpers.php";
require_once "$docroot/webGui/include/publish.php";
@@ -114,13 +117,23 @@ while (true) {
elseif (exec("zpool status|grep -c 'scrub in progress'")>0) $process = 4;
else $process = 0;
publish('parity', implode(';',$data));
if (time()-$timer >= 2) {
// update every 2 seconds
$echo = implode(';',$data);
$md5_new = md5($echo,true);
if ($md5_new !== $md5_old) {
publish('parity', $echo);
$md5_old = $md5_new;
}
if ($spot !== $spot_old) {
publish('paritymonitor', $spot>0 ? 1 : 0);
$spot_old = $spot;
}
if ($fsState !== $fs_old) {
publish('fsState', $fsState);
$fs_old = $fsState;
}
if ($process !== $proc_old) {
publish('mymonitor', $process);
$timer = time();
$proc_old = $process;
}
sleep(1);
}
+7 -1
View File
@@ -14,6 +14,7 @@
<?
$docroot = '/usr/local/emhttp';
$varroot = '/var/local/emhttp';
$md5_old = -1;
require_once "$docroot/webGui/include/publish.php";
while (true) {
@@ -32,7 +33,12 @@ while (true) {
foreach ($names as $name) $count[] = $counts[$name] ?? 0;
$count = implode("\0",$count);
publish('update1', "$info\1$rpms\1$count");
$echo = "$info\1$rpms\1$count";
$md5_new = md5($echo,true);
if ($md5_new !== $md5_old) {
publish('update1', $echo);
$md5_old = $md5_new;
}
sleep(5);
}
?>
+7 -1
View File
@@ -16,6 +16,7 @@ $docroot = '/usr/local/emhttp';
$varroot = '/var/local/emhttp';
$stamps = '/var/tmp/stamps.ini';
$resync = '/var/tmp/resync.ini';
$md5_old = -1;
require_once "$docroot/webGui/include/Helpers.php";
require_once "$docroot/webGui/include/publish.php";
@@ -463,7 +464,12 @@ while (true) {
$echo[4] .= _('Scheduled parity check is disabled');
}
}
publish('update2', implode("\1",$echo));
$echo = implode("\1",$echo);
$md5_new = md5($echo,true);
if ($md5_new !== $md5_old) {
publish('update2', $echo);
$md5_old = $md5_new;
}
sleep(5);
}
?>
+7 -2
View File
@@ -25,7 +25,7 @@ require_once "$docroot/webGui/include/Translations.php";
// remember current language
$locale_init = $locale;
$md5_old = -1;
$state = [
'ONLINE' => _('Online'),
'SLAVE' => '('._('slave').')',
@@ -121,7 +121,12 @@ while (true) {
elseif (isset($load)) $status[5] = ($load<90 ? "<span>" : "<span $red>").$status[5]."</span>";
$status[6] = isset($output) ? ((!$volt || ($minv<$output && $output<$maxv) ? "<span $green>" : "<span $red>").$status[6].(isset($freq) ? " ~ $freq Hz" : "")."</span>") : $status[6];
}
publish('apcups',implode(';', $status));
$echo = implode(';', $status);
$md5_new = md5($echo,true);
if ($md5_new !== $md5_old) {
publish('apcups', $echo);
$md5_old = $md5_new;
}
sleep(3);
}
?>
+7 -1
View File
@@ -27,6 +27,7 @@ function my_scale($value, &$unit) {
return number_format($value, $decimals, '.', $value>9999 ? ',':'');
}
$md5_old = -1;
while (true) {
$now = time(); $i = 0;
unset($dump); $vtun = [];
@@ -35,7 +36,12 @@ while (true) {
$row = preg_split('/\s+/',$row);
if (count($row)>5) $vtun[] = $row[0].';'.($row[5] ? $now - $row[5] : 0).';'.my_scale($row[6],$unit)." $unit;".my_scale($row[7],$unit)." $unit";
}
publish('wireguard', implode("\0",$vtun));
$echo = implode("\0",$vtun);
$md5_new = md5($echo,true);
if ($md5_new !== $md5_old) {
publish('wireguard', $echo);
$md5_old = $md5_new;
}
sleep(1);
}
?>