forked from laysense/laysite
Address system information and license review suggestions
This commit is contained in:
@@ -7,22 +7,26 @@ jQuery(function ($) {
|
||||
const $cpu = $metrics.find('[data-about-cpu]');
|
||||
const $memory = $metrics.find('[data-about-memory]');
|
||||
const percent = new Intl.NumberFormat('zh-CN', {style: 'percent', maximumFractionDigits: 1});
|
||||
const {cpuTotal, cpuIdle} = $metrics[0].dataset;
|
||||
let previous = cpuTotal === '' ? null : {total: Number(cpuTotal), idle: Number(cpuIdle)};
|
||||
let previous = null;
|
||||
let timer = null;
|
||||
let pending = null;
|
||||
let sessionExpired = false;
|
||||
if (previous) $cpu.text('采样中…');
|
||||
|
||||
function active() {
|
||||
return $metrics[0].open && !document.hidden && !sessionExpired;
|
||||
}
|
||||
|
||||
function poll() {
|
||||
if (document.hidden) {
|
||||
previous = null;
|
||||
window.setTimeout(poll, 5000);
|
||||
return;
|
||||
}
|
||||
timer = null;
|
||||
if (!active()) return;
|
||||
|
||||
$.ajax({url: '/admin/about/metrics', dataType: 'json', timeout: 4000})
|
||||
let delay = 5000;
|
||||
pending = $.ajax({url: '/admin/about/metrics', dataType: 'json', timeout: 4000});
|
||||
pending
|
||||
.done(({cpu, memory}) => {
|
||||
if (!cpu || !previous || cpu.total <= previous.total) {
|
||||
$cpu.text(cpu ? '采样中…' : '暂不可用');
|
||||
if (cpu) delay = 1000;
|
||||
} else {
|
||||
const total = cpu.total - previous.total;
|
||||
const idle = cpu.idle - previous.idle;
|
||||
@@ -31,7 +35,8 @@ jQuery(function ($) {
|
||||
previous = cpu;
|
||||
$memory.text(memory ?? '暂不可用');
|
||||
})
|
||||
.fail(({status}) => {
|
||||
.fail(({status}, reason) => {
|
||||
if (reason === 'abort') return;
|
||||
previous = null;
|
||||
sessionExpired = status === 401;
|
||||
const message = sessionExpired ? '登录已过期' : '暂不可用';
|
||||
@@ -39,9 +44,26 @@ jQuery(function ($) {
|
||||
$memory.text(message);
|
||||
})
|
||||
.always(() => {
|
||||
if (!sessionExpired) window.setTimeout(poll, 5000);
|
||||
pending = null;
|
||||
if (active()) timer = window.setTimeout(poll, delay);
|
||||
});
|
||||
}
|
||||
|
||||
window.setTimeout(poll, 1000);
|
||||
function sync() {
|
||||
if (active()) {
|
||||
if (timer === null && pending === null) {
|
||||
$cpu.text('采样中…');
|
||||
poll();
|
||||
}
|
||||
return;
|
||||
}
|
||||
window.clearTimeout(timer);
|
||||
timer = null;
|
||||
previous = null;
|
||||
pending?.abort();
|
||||
}
|
||||
|
||||
$metrics.on('toggle', sync);
|
||||
$(document).on('visibilitychange', sync);
|
||||
sync();
|
||||
});
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
.admin-system-info dt { color: var(--muted); }
|
||||
.admin-system-info dd { margin: 0; font-family: var(--mono); overflow-wrap: anywhere; }
|
||||
.admin-system-info dd small { display: block; font-family: var(--sans); color: var(--muted); }
|
||||
.admin-system-info .field-note { margin-block-end: 1rem; }
|
||||
.admin-system-info .admin-about-details { margin-block-start: .75rem; }
|
||||
.admin-system-info .field-note { margin-block: .5rem 0; }
|
||||
.admin-about-details { background: var(--paper); }
|
||||
.admin-license-project { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .65rem 1rem; margin-bottom: 1rem; }
|
||||
.admin-license-project p { margin: .2rem 0 0; color: var(--muted); }
|
||||
|
||||
Reference in New Issue
Block a user