Main page: use Nchan for parity status updates

This commit is contained in:
bergware
2021-05-25 20:09:01 +02:00
parent 201b1275eb
commit 24ef2535d0
2 changed files with 14 additions and 76 deletions

View File

@@ -1,7 +1,7 @@
Menu="Main:5"
Title="Array Operation"
Tag="snowflake-o"
Nchan="device_list,disk_load"
Nchan="device_list,disk_load,parity_list"
---
<?PHP
/* Copyright 2005-2021, Lime Technology
@@ -179,17 +179,6 @@ function tab0() {
$.removeCookie('one',{path:'/'});
$.cookie('tab','tab0',{path:'/'});
}
function parityStatus() {
$.post('/webGui/include/ParityList.php',{},function(data) {
if (data) {$.each(data.split(';'),function(k,v) {if ($('#line'+k).length>0) $('#line'+k).html(v);});}
timers.parityStatus = setTimeout(parityStatus,3000);
if (!data && $('#cancelButton').length>0 && $('#cancelButton').val()=="_(Cancel)_") {
$('#cancelButton').val('Done').prop('onclick',null).off('click').click(function(){refresh();});
$('#cancelText').html('');
$('#line4').html("_(completed)_");
}
});
}
function stopArray(form) {
$(form).append('<input type="hidden" name="cmdStop" value="Stop">');
devices.stop();
@@ -232,7 +221,6 @@ function shutdown_now(form,cmd) {
function toggleApply(checked) {
$('input[name="#apply"]').prop('disabled',!checked);
}
parityStatus();
<?if ($tabbed):?>
$('.tabs').append(ctrl);
if ($.cookie('tab')=='tab0') $('i.toggle').hide();
@@ -283,7 +271,20 @@ devices.on('connect', function(e) {
});
<?endif;?>
var parityStatus = new NchanSubscriber('/sub/parity');
parityStatus.on('message', function(data) {
$.each(data.split(';'),function(k,v) {if ($('#line'+k).length>0) $('#line'+k).html(v);});
if (!data && $('#cancelButton').length>0 && $('#cancelButton').val()=="_(Cancel)_") {
$('#cancelButton').val('Done').prop('onclick',null).off('click').click(function(){refresh();});
$('#cancelText').html('');
$('#line4').html("_(completed)_");
}
});
devices.start();
<?if ($var['mdResyncPos']):?>
parityStatus.start();
<?endif;?>
$(function(){
var form = document.arrayOps;
if (form.input !== undefined) selectInput(form);

View File

@@ -1,63 +0,0 @@
<?PHP
/* Copyright 2005-2021, Lime Technology
* Copyright 2012-2021, 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 = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
// add translations
$_SERVER['REQUEST_URI'] = 'main';
require_once "$docroot/webGui/include/Translations.php";
require_once "$docroot/webGui/include/Helpers.php";
$var = (array)parse_ini_file('state/var.ini');
extract(parse_plugin_cfg('dynamix',true));
function in_parity_log($log,$timestamp) {
if (file_exists($log)) {
$handle = fopen($log, 'r');
while (($line = fgets($handle))!==false) {
if (strpos($line,$timestamp)!==false) break;
}
fclose($handle);
}
return !empty($line);
}
function my_clock($time) {
if (!$time) return _('less than a minute');
$days = floor($time/1440);
$hour = $time/60%24;
$mins = $time%60;
return plus($days,'day',($hour|$mins)==0).plus($hour,'hour',$mins==0).plus($mins,'minute',true);
}
$data = [];
if ($var['mdResyncPos']) {
$data[] = my_scale($var['mdResyncSize']*1024,$unit,-1)." $unit";
$data[] = _(my_clock(floor((time()-$var['sbSynced'])/60)),2).($var['mdResyncDt'] ? '' : ' ('._('paused').')');
$data[] = my_scale($var['mdResyncPos']*1024,$unit)." $unit (".number_format(($var['mdResyncPos']/($var['mdResyncSize']/100+1)),1,$display['number'][0],'')." %)";
$data[] = $var['mdResyncDt'] ? my_scale($var['mdResyncDb']*1024/$var['mdResyncDt'],$unit, 1)." $unit/sec" : '---';
$data[] = $var['mdResyncDb'] ? _(my_clock(round(((($var['mdResyncDt']*(($var['mdResyncSize']-$var['mdResyncPos'])/($var['mdResyncDb']/100+1)))/100)/60),0)),2) : _('Unknown');
$data[] = $var['sbSyncErrs'];
echo implode(';',$data);
} else {
if ($var['sbSynced']==0 || $var['sbSynced2']==0) exit;
$log = '/boot/config/parity-checks.log';
$timestamp = str_replace(['.0','.'],[' ',' '],date('M.d H:i:s',$var['sbSynced2']));
if (in_parity_log($log,$timestamp)) exit;
$duration = $var['sbSynced2'] - $var['sbSynced'];
$status = $var['sbSyncExit'];
$speed = ($status==0) ? my_scale($var['mdResyncSize']*1024/$duration,$unit,1)." $unit/s" : _('Unavailable');
$error = $var['sbSyncErrs'];
$year = date('Y',$var['sbSynced2']);
if ($status==0||file_exists($log)) file_put_contents($log,"$year $timestamp|$duration|$speed|$status|$error\n",FILE_APPEND);
}
?>