webGui: new watchdog service with websockets instead of ajax polling

This commit is contained in:
Eric Schultz
2017-05-08 08:11:11 -05:00
parent 89f7fcbba4
commit f55f57515d
2 changed files with 40 additions and 17 deletions
+4 -17
View File
@@ -245,21 +245,6 @@ function closeNotifier(filter) {
function viewHistory(filter) {
location.replace('/Tools/NotificationsArchive?filter='+filter);
}
function watchdog() {
$.post('/webGui/include/Watchdog.php',{mode:<?=$display['refresh']?>,dot:'<?=$display['number'][0]?>'},function(data) {
if (data) {
$.each(data.split('#'),function(k,v) {
<?if ($update):?>
if (v!='stop') $('#statusbar').html(v); else setTimeout(refresh,0);
});
timers.watchdog = setTimeout(watchdog,<?=abs($display['refresh'])?>);
<?else:?>
if (v!='stop') $('#statusbar').html(v);
});
<?endif;?>
}
});
}
function countDown() {
counting--;
if (counting==0) counting = update;
@@ -419,7 +404,6 @@ $(function() {
form.find('input[value="Apply"],input[name="cmdEditShare"],input[name="cmdUserEdit"]').removeAttr('disabled');
form.find('input[value="Done"]').val('Reset').prop('onclick',null).click(function(){refresh(form.offset().top)});
});});
timers.watchdog = setTimeout(watchdog,50);
var top = ($.cookie('top')||0) - $('.tabs').offset().top - 75;
if (top>0) {$('html,body').scrollTop(top);}
$.removeCookie('top',{path:'/'});
@@ -486,7 +470,10 @@ $(function() {
}
$('form').append($('<input>').attr({type:'hidden', name:'csrf_token', value:'<?=$var['csrf_token']?>'}));
var watchdog = new NchanSubscriber('/sub/watchdog');
watchdog.on('message', function(data){$('#statusbar').html(data);});
watchdog.start();
});
</script>
</body>
</html>
</html>
+36
View File
@@ -0,0 +1,36 @@
#!/bin/bash
PREV=
while :; do
. /var/local/emhttp/var.ini
case $fsState in
Stopped)
DATA="<span class='red strong'>Array Stopped</span>"
;;
Starting)
DATA="<span class='orange strong'>Array Starting</span>"
;;
*)
DATA="<span class='green strong'>Array Started</span>"
;;
esac
if [[ $mdResync -gt 0 ]]; then
MODE=
if [[ $mdResyncAction =~ recon ]]; then
MODE='Parity-Sync / Data-Rebuild'
elif [[ $mdResyncAction =~ clear ]]; then
MODE='Clearing'
elif [[ $mdResyncAction == check ]]; then
MODE='Read-Check'
elif [[ $mdResyncAction =~ check ]]; then
MODE='Parity-Check'
fi
p=$((mdResyncPos*1000/mdResync)); w=${p:0:-1}
DATA="$DATA&bullet;<span class='orange strong'>$MODE ${w:-0}.${p: -1} %</span>"
fi
if [[ $DATA != $PREV ]]; then
curl -s -X POST -d "$DATA" http://127.0.0.1/pub/watchdog?buffer_length=1 &>/dev/null
PREV=$DATA
fi
sleep 3
done &