452 |
452 |
<div id="cpuPB" class="progress-bar progress-bar-striped" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%">
|
453 |
453 |
</div>
|
454 |
454 |
</div>
|
455 |
|
|
456 |
|
<span id="cpumeter"></span>
|
|
455 |
<span id="cpumeter"><?=sprintf(gettext("Retrieving CPU data %s"), "<i class=\"fa fa-gear fa-spin\"></i>")?></span>
|
457 |
456 |
</td>
|
458 |
457 |
</tr>
|
459 |
458 |
<?php
|
... | ... | |
573 |
572 |
set_widget_checkbox_events("#widget-<?=$widgetname?>_panel-footer [id^=show]", "showallsysinfoitems");
|
574 |
573 |
});
|
575 |
574 |
|
|
575 |
var lastTotal = 0;
|
|
576 |
var lastUsed = 0;
|
|
577 |
|
576 |
578 |
function setProgress(barName, percent) {
|
577 |
579 |
$('#' + barName).css('width', percent + '%').attr('aria-valuenow', percent);
|
578 |
580 |
}
|
... | ... | |
586 |
588 |
return false;
|
587 |
589 |
}))
|
588 |
590 |
|
589 |
|
updateUptime(values[2]);
|
590 |
|
updateDateTime(values[5]);
|
591 |
|
updateCPU(values[0]);
|
592 |
|
updateMemory(values[1]);
|
593 |
|
updateState(values[3]);
|
594 |
|
updateTemp(values[4]);
|
595 |
|
updateInterfaceStats(values[6]);
|
596 |
|
updateInterfaces(values[7]);
|
597 |
|
updateCpuFreq(values[8]);
|
598 |
|
updateLoadAverage(values[9]);
|
599 |
|
updateMbuf(values[10]);
|
600 |
|
updateMbufMeter(values[11]);
|
601 |
|
updateStateMeter(values[12]);
|
|
591 |
if (lastTotal === 0) {
|
|
592 |
lastTotal = values[0];
|
|
593 |
lastUsed = values[1];
|
|
594 |
} else {
|
|
595 |
updateCPU(values[0], values[1]);
|
|
596 |
}
|
|
597 |
|
|
598 |
updateUptime(values[3]);
|
|
599 |
updateDateTime(values[6]);
|
|
600 |
updateMemory(values[2]);
|
|
601 |
updateState(values[4]);
|
|
602 |
updateTemp(values[5]);
|
|
603 |
updateCpuFreq(values[7]);
|
|
604 |
updateLoadAverage(values[8]);
|
|
605 |
updateMbuf(values[9]);
|
|
606 |
updateMbufMeter(values[10]);
|
|
607 |
updateStateMeter(values[11]);
|
602 |
608 |
}
|
603 |
609 |
|
604 |
610 |
function updateMemory(x) {
|
... | ... | |
625 |
631 |
}
|
626 |
632 |
}
|
627 |
633 |
|
628 |
|
function updateCPU(x) {
|
|
634 |
function updateCPU(total, used) {
|
|
635 |
if ((lastTotal <= total) && (lastUsed <= used)) { // Just in case it wraps
|
|
636 |
// Calculate the total ticks and the used ticks sine the last time it was checked
|
|
637 |
var d_total = total - lastTotal;
|
|
638 |
var d_used = used - lastUsed;
|
629 |
639 |
|
630 |
|
if ($('#cpumeter')) {
|
631 |
|
$("#cpumeter").html(x + '%');
|
632 |
|
}
|
633 |
|
if ($('#cpuPB')) {
|
634 |
|
setProgress('cpuPB', parseInt(x));
|
635 |
|
}
|
|
640 |
// Convert to percent
|
|
641 |
var x = Math.trunc( ((d_total - d_used)/d_total) * 100);
|
636 |
642 |
|
637 |
|
/* Load CPU Graph widget if enabled */
|
638 |
|
if (widgetActive('cpu_graphs')) {
|
639 |
|
GraphValue(graph[0], x);
|
|
643 |
if ($('#cpumeter')) {
|
|
644 |
$('[id="cpumeter"]').html(x + '%');
|
|
645 |
}
|
|
646 |
|
|
647 |
if ($('#cpuPB')) {
|
|
648 |
setProgress('cpuPB', parseInt(x));
|
|
649 |
}
|
|
650 |
|
|
651 |
/* Load CPU Graph widget if enabled */
|
|
652 |
if (widgetActive('cpu_graphs')) {
|
|
653 |
GraphValue(graph[0], x);
|
|
654 |
}
|
640 |
655 |
}
|
|
656 |
|
|
657 |
// Update the saved "last" values
|
|
658 |
lastTotal = total;
|
|
659 |
lastUsed = used;
|
641 |
660 |
}
|
642 |
661 |
|
643 |
662 |
function updateTemp(x) {
|
Revise CPU load display to eliminate sleep in AJAX call
(cherry picked from commit c4ec696bf9eae3f8dbbad30b2e0804b9bf7de4b6)