389 |
389 |
</div>
|
390 |
390 |
</div>
|
391 |
391 |
<?php $update_period = (!empty($config['widgets']['period'])) ? $config['widgets']['period'] : "10"; ?>
|
392 |
|
<span id="cpumeter"><?=sprintf(gettext("Updating in %s seconds"), $update_period)?></span>
|
|
392 |
<span id="cpumeter"><?=sprintf(gettext("Retrieving CPU data %s"), "<i class=\"fa fa-gear fa-spin\"></i>")?></span>
|
393 |
393 |
</td>
|
394 |
394 |
</tr>
|
395 |
395 |
<?php
|
... | ... | |
508 |
508 |
//<![CDATA[
|
509 |
509 |
<?php if ($widget_first_instance): ?>
|
510 |
510 |
|
511 |
|
var update_interval = "<?=$widgetperiod?>";
|
|
511 |
var lastTotal = 0;
|
|
512 |
var lastUsed = 0;
|
512 |
513 |
|
513 |
514 |
function setProgress(barName, percent) {
|
514 |
515 |
$('[id="' + barName + '"]').css('width', percent + '%').attr('aria-valuenow', percent);
|
... | ... | |
523 |
524 |
return false;
|
524 |
525 |
}))
|
525 |
526 |
|
526 |
|
updateUptime(values[2]);
|
527 |
|
updateDateTime(values[5]);
|
528 |
|
updateCPU(values[0]);
|
529 |
|
updateMemory(values[1]);
|
530 |
|
updateState(values[3]);
|
531 |
|
updateTemp(values[4]);
|
532 |
|
updateCpuFreq(values[6]);
|
533 |
|
updateLoadAverage(values[7]);
|
534 |
|
updateMbuf(values[8]);
|
535 |
|
updateMbufMeter(values[9]);
|
536 |
|
updateStateMeter(values[10]);
|
|
527 |
if (lastTotal === 0) {
|
|
528 |
lastTotal = values[0];
|
|
529 |
lastUsed = values[1];
|
|
530 |
} else {
|
|
531 |
updateCPU(values[0], values[1]);
|
|
532 |
}
|
|
533 |
|
|
534 |
updateUptime(values[3]);
|
|
535 |
updateDateTime(values[6]);
|
|
536 |
updateMemory(values[2]);
|
|
537 |
updateState(values[4]);
|
|
538 |
updateTemp(values[5]);
|
|
539 |
updateCpuFreq(values[7]);
|
|
540 |
updateLoadAverage(values[8]);
|
|
541 |
updateMbuf(values[9]);
|
|
542 |
updateMbufMeter(values[10]);
|
|
543 |
updateStateMeter(values[11]);
|
537 |
544 |
}
|
538 |
545 |
|
539 |
546 |
function updateMemory(x) {
|
... | ... | |
560 |
567 |
}
|
561 |
568 |
}
|
562 |
569 |
|
563 |
|
function updateCPU(x) {
|
|
570 |
function updateCPU(total, used) {
|
564 |
571 |
|
565 |
|
if ($('#cpumeter')) {
|
566 |
|
$('[id="cpumeter"]').html(x + '%');
|
567 |
|
}
|
568 |
|
if ($('#cpuPB')) {
|
569 |
|
setProgress('cpuPB', parseInt(x));
|
570 |
|
}
|
|
572 |
// Just in case it wraps
|
|
573 |
if ((lastTotal <= total) && (lastUsed <= used)) {
|
|
574 |
// Calculate the total ticks and the used ticks sine the last time it was checked
|
|
575 |
var d_total = total - lastTotal;
|
|
576 |
var d_used = used - lastUsed;
|
|
577 |
|
|
578 |
// Convert to percent
|
|
579 |
var x = Math.trunc( ((d_total - d_used)/d_total) * 100);
|
571 |
580 |
|
572 |
|
/* Load CPU Graph widget if enabled */
|
573 |
|
if (widgetActive('cpu_graphs')) {
|
574 |
|
GraphValue(graph[0], x);
|
|
581 |
if ($('#cpumeter')) {
|
|
582 |
$('[id="cpumeter"]').html(x + '%');
|
|
583 |
}
|
|
584 |
|
|
585 |
if ($('#cpuPB')) {
|
|
586 |
setProgress('cpuPB', parseInt(x));
|
|
587 |
}
|
|
588 |
|
|
589 |
/* Load CPU Graph widget if enabled */
|
|
590 |
if (widgetActive('cpu_graphs')) {
|
|
591 |
GraphValue(graph[0], x);
|
|
592 |
}
|
575 |
593 |
}
|
|
594 |
|
|
595 |
lastTotal = total;
|
|
596 |
lastUsed = used;
|
576 |
597 |
}
|
577 |
598 |
|
578 |
599 |
function updateTemp(x) {
|
Re-write CPU usage calculation to avoid sleep in AJAX call