Strengthen push device health checks
This commit is contained in:
@@ -1673,6 +1673,20 @@ function control_api_dispatch(): void
|
||||
'ok' => true,
|
||||
'data' => [
|
||||
'devices' => push_device_rows(),
|
||||
'summary' => push_health_summary(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
if ($action === 'send_push_healthcheck') {
|
||||
require_csrf();
|
||||
|
||||
json_out([
|
||||
'ok' => true,
|
||||
'data' => [
|
||||
'result' => send_push_healthcheck_if_due(24, true),
|
||||
'devices' => push_device_rows(),
|
||||
'summary' => push_health_summary(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
@@ -1691,6 +1705,7 @@ function control_api_dispatch(): void
|
||||
'ok' => true,
|
||||
'data' => [
|
||||
'devices' => push_device_rows(),
|
||||
'summary' => push_health_summary(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
@@ -1702,6 +1717,7 @@ function control_api_dispatch(): void
|
||||
'ok' => true,
|
||||
'data' => [
|
||||
'devices' => push_device_rows(),
|
||||
'summary' => push_health_summary(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
+44
-4
@@ -28,6 +28,7 @@
|
||||
noticeBaseline: $('#noticeBaseline'),
|
||||
pushStatus: $('#pushStatus'),
|
||||
pushDeviceList: $('#pushDeviceList'),
|
||||
pushHealthcheckBtn: $('#pushHealthcheckBtn'),
|
||||
processCpuTable: $('#processCpuTable'),
|
||||
processMemoryTable: $('#processMemoryTable'),
|
||||
dmesgToggle: $('#dmesgToggle'),
|
||||
@@ -324,6 +325,11 @@
|
||||
return formatDhms(parseWifiDurationSeconds(value)) || value;
|
||||
}
|
||||
|
||||
function timeAgo(seconds) {
|
||||
const formatted = formatDhms(seconds);
|
||||
return formatted ? `${formatted} ago` : '-';
|
||||
}
|
||||
|
||||
function renderWifi(data) {
|
||||
const rows = data.wifi?.clients || [];
|
||||
if (!els.wifiTable) return;
|
||||
@@ -522,18 +528,34 @@
|
||||
: '<div class="spike-log-empty">No system notice history.</div>';
|
||||
}
|
||||
|
||||
function renderPushDevices(devices = []) {
|
||||
function renderPushDevices(devices = [], summary = null) {
|
||||
if (!els.pushDeviceList) return;
|
||||
|
||||
if (summary && els.pushStatus) {
|
||||
const total = Number(summary.total || 0);
|
||||
const healthy = Number(summary.healthy || 0);
|
||||
const watch = Number(summary.watch || 0);
|
||||
const stale = Number(summary.stale || 0);
|
||||
const failed = Number(summary.failed || 0);
|
||||
const pending = Number(summary.pending || 0);
|
||||
els.pushStatus.textContent = `Push devices: ${total} total / ${healthy} healthy / ${watch} watch / ${stale} stale / ${failed} failed / ${pending} pending`;
|
||||
}
|
||||
|
||||
els.pushDeviceList.innerHTML = devices.length
|
||||
? devices.map(device => `
|
||||
<div class="push-device-row">
|
||||
<div class="push-device-row ${escapeHtml(device.health_status || 'pending')}">
|
||||
<div class="push-device-main">
|
||||
<strong>${escapeHtml(device.device_name || '이름 없음')}</strong>
|
||||
<span class="push-device-badge ${escapeHtml(device.health_status || 'pending')}">${escapeHtml(device.health_text || '수신 대기')}</span>
|
||||
<span>Host: ${escapeHtml(device.host || 'unknown')}</span>
|
||||
<span>IP: ${escapeHtml(device.actor_ip || '-')}</span>
|
||||
<span>Created: ${escapeHtml(device.created_at || '-')}</span>
|
||||
<span>Last seen: ${escapeHtml(device.last_seen_at || '-')}</span>
|
||||
<span>Registered refresh: ${escapeHtml(device.last_seen_at || '-')} (${escapeHtml(timeAgo(device.last_seen_seconds))})</span>
|
||||
<span>Last send success: ${escapeHtml(device.last_send_success_at || '-')} (${escapeHtml(timeAgo(device.last_send_success_seconds))})</span>
|
||||
<span>Last received: ${escapeHtml(device.last_received_at || '-')} (${escapeHtml(timeAgo(device.last_received_seconds))})</span>
|
||||
<span>Last shown: ${escapeHtml(device.last_notification_at || '-')} (${escapeHtml(timeAgo(device.last_notification_seconds))})</span>
|
||||
<span>Last click: ${escapeHtml(device.last_click_at || '-')}</span>
|
||||
<span>Failures: ${Number(device.failure_count || 0).toLocaleString()}${device.last_failure_reason ? ` / ${escapeHtml(device.last_failure_reason)}` : ''}</span>
|
||||
<span>Encoding: ${escapeHtml(device.content_encoding || '-')}</span>
|
||||
<span>Hash: ${escapeHtml(device.hash || '-')}</span>
|
||||
<span>Endpoint: ${escapeHtml(device.endpoint || '-')}</span>
|
||||
@@ -582,12 +604,28 @@
|
||||
state.pushDevicesLastRefresh = Date.now();
|
||||
try {
|
||||
const data = await api('push_devices');
|
||||
renderPushDevices(data.devices || []);
|
||||
renderPushDevices(data.devices || [], data.summary || null);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
async function sendPushHealthcheck() {
|
||||
if (!els.pushHealthcheckBtn) return;
|
||||
|
||||
els.pushHealthcheckBtn.disabled = true;
|
||||
try {
|
||||
const data = await api('send_push_healthcheck', {});
|
||||
renderPushDevices(data.devices || [], data.summary || null);
|
||||
const result = data.result || {};
|
||||
notice(`Health check sent ${Number(result.sent || 0)} / failed ${Number(result.failed || 0)}`, result.failed ? 'error' : 'success');
|
||||
} catch (e) {
|
||||
notice(e.message || 'Health check failed', 'error');
|
||||
} finally {
|
||||
els.pushHealthcheckBtn.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener('pushdevices:refresh', () => {
|
||||
refreshPushDevices(true);
|
||||
});
|
||||
@@ -596,6 +634,8 @@
|
||||
renderPushStatus(event.detail || {});
|
||||
});
|
||||
|
||||
els.pushHealthcheckBtn?.addEventListener('click', sendPushHealthcheck);
|
||||
|
||||
function renderFanCause(data) {
|
||||
const processes = data.processes || {};
|
||||
const baseline = data.fan_spike || {};
|
||||
|
||||
+8
-3
@@ -105,7 +105,7 @@ a{color:inherit;text-decoration:none}
|
||||
.table-wrap{max-width:100%;overflow-x:auto;overflow-y:hidden;-webkit-overflow-scrolling:touch;border-radius:16px;border:1px solid var(--line)}.wifi-table{width:100%;min-width:1080px;table-layout:fixed;border-collapse:collapse}.wifi-table th,.wifi-table td{padding:11px 13px;border-bottom:1px solid rgba(255,255,255,.06);text-align:left;font-size:14px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.wifi-table th{position:sticky;top:0;background:#1d2330;z-index:1;font-weight:500}.wifi-table tr:hover{background:rgba(255,255,255,.03)}.wifi-table .col-band{width:72px}.wifi-table .col-host{width:240px}.wifi-table .col-ip{width:132px}.wifi-table .col-mac{width:170px}.wifi-table .col-signal{width:100px}.wifi-table .col-rate{width:120px}.wifi-table .col-time{width:130px}
|
||||
.chart-grid{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:14px}.chart-box{height:280px;background:#11151d;border:1px solid rgba(84,101,128,.58);border-radius:16px;padding:12px 12px 18px}.chart-box h3{margin:0 0 8px;color:#c6d3e6;font-size:13px}.chart-canvas{position:relative;height:calc(100% - 27px);min-height:0}.chart-canvas canvas{width:100%!important;height:100%!important}
|
||||
.resource-card{margin-top:18px}.resource-head{display:flex;align-items:baseline;justify-content:space-between;gap:12px;margin-bottom:16px}.resource-head h2{margin:0}.baseline-pill{color:var(--sub);font-size:12px;font-variant-numeric:tabular-nums;text-align:right;white-space:nowrap}.spike-log-box{margin-top:16px}.spike-log-box h3{margin:0 0 9px;color:#c6d3e6;font-size:14px;font-weight:500}.spike-log-list{display:grid;gap:8px;max-height:260px;overflow:auto;padding-right:4px}.spike-log-item{display:grid;gap:4px;padding:10px 12px;border:1px solid rgba(255,204,0,.35);background:rgba(138,109,27,.16);border-radius:12px}.spike-log-item.latest{border:1px solid rgba(255,204,0,.58);background:rgba(138,109,27,.28);box-shadow:0 0 0 1px rgba(255,204,0,.14) inset;}.spike-log-item strong{font-size:13px;font-weight:500;color:#f3e3a3}.spike-log-item span{font-size:12px;color:var(--sub);font-variant-numeric:tabular-nums}.spike-log-empty{padding:10px 12px;border-radius:12px;background:var(--card2);color:var(--sub);font-size:13px}.dmesg-head{display:flex;align-items:center;justify-content:space-between;gap:10px}.dmesg-meta{font-size:12px;color:var(--sub);font-variant-numeric:tabular-nums}.dmesg-log{margin:10px 0 0;max-height:420px;overflow:auto;border:1px solid var(--line);border-radius:12px;background:#070a10;color:#d9e2f2;padding:12px;font:12px/1.45 ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;white-space:pre-wrap;word-break:break-word}.dmesg-log[hidden]{display:none}
|
||||
.resource-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:14px}.resource-box{min-width:0}.resource-box h3{margin:0 0 9px;color:#c6d3e6;font-size:14px;font-weight:500}.resource-table{width:100%;min-width:620px;table-layout:fixed;border-collapse:collapse;border:1px solid var(--line);border-radius:14px;overflow:hidden}.resource-table th,.resource-table td{padding:9px 10px;border-bottom:1px solid rgba(255,255,255,.06);background:#11151d;text-align:left;font-size:13px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.resource-table th{background:#1d2330;color:#c6d3e6;font-weight:500}.resource-table .pid{width:72px}.resource-table .metric{width:82px}.resource-table .service{width:150px}.resource-table .cmd{width:auto}.push-device-list{display:grid;gap:8px;margin-top:8px}.push-device-row{padding:10px 12px;border:1px solid rgba(84,101,128,.58);background:#11151d;border-radius:12px}.push-device-main{min-width:0;color:var(--sub);font-size:12px;line-height:1.45;display:grid;gap:2px;word-break:break-all}.push-device-main strong{color:#edf1f7;font-size:13px}
|
||||
.resource-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:14px}.resource-box{min-width:0}.resource-box h3{margin:0 0 9px;color:#c6d3e6;font-size:14px;font-weight:500}.resource-table{width:100%;min-width:620px;table-layout:fixed;border-collapse:collapse;border:1px solid var(--line);border-radius:14px;overflow:hidden}.resource-table th,.resource-table td{padding:9px 10px;border-bottom:1px solid rgba(255,255,255,.06);background:#11151d;text-align:left;font-size:13px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.resource-table th{background:#1d2330;color:#c6d3e6;font-weight:500}.resource-table .pid{width:72px}.resource-table .metric{width:82px}.resource-table .service{width:150px}.resource-table .cmd{width:auto}.push-device-head{display:flex;align-items:center;justify-content:space-between;gap:10px}.push-device-actions{display:flex;gap:8px;flex-wrap:wrap}.push-device-list{display:grid;gap:8px;margin-top:8px}.push-device-row{padding:10px 12px;border:1px solid rgba(84,101,128,.58);background:#11151d;border-radius:12px}.push-device-row.healthy{border-color:rgba(53,196,107,.45)}.push-device-row.watch{border-color:rgba(255,204,0,.48)}.push-device-row.stale,.push-device-row.failed{border-color:rgba(255,95,87,.55)}.push-device-main{min-width:0;color:var(--sub);font-size:12px;line-height:1.45;display:grid;gap:2px;word-break:break-all}.push-device-main strong{color:#edf1f7;font-size:13px}.push-device-badge{display:inline-flex;align-items:center;width:max-content;border-radius:999px;padding:2px 8px;background:#2b3342;color:#edf1f7;font-size:11px}.push-device-badge.healthy{background:#198754}.push-device-badge.watch{background:#8a6d1b}.push-device-badge.stale,.push-device-badge.failed{background:#c62828}
|
||||
.notice{position:fixed;right:20px;bottom:20px;min-width:220px;max-width:420px;padding:14px 16px;border-radius:14px;font-weight:500;background:#1d2330;border:1px solid var(--line);box-shadow:var(--shadow);z-index:99}.notice:empty{display:none}.notice[data-type=success]{border-color:rgba(53,196,107,.5)}.notice[data-type=error]{border-color:rgba(255,95,87,.5)}
|
||||
@media(max-width:1320px){.chart-grid{grid-template-columns:repeat(2,minmax(0,1fr))}}
|
||||
@media(max-width:1100px){.layout{grid-template-columns:1fr}.chart-grid,.resource-grid{grid-template-columns:1fr}.topbar{align-items:flex-start;flex-direction:column}.topbar-right{width:100%}.topbar-right .btn{flex:1}.stat-grid{grid-template-columns:1fr}.resource-head{align-items:flex-start;flex-direction:column}.baseline-pill{text-align:left;white-space:normal}}
|
||||
@@ -260,7 +260,12 @@ a{color:inherit;text-decoration:none}
|
||||
</div>
|
||||
|
||||
<div class="spike-log-box">
|
||||
<h3>Push Devices</h3>
|
||||
<div class="push-device-head">
|
||||
<h3>Push Devices</h3>
|
||||
<div class="push-device-actions">
|
||||
<button class="btn secondary" id="pushHealthcheckBtn" type="button">Health Check</button>
|
||||
</div>
|
||||
</div>
|
||||
<div id="pushStatus" class="spike-log-empty">Push status checking...</div>
|
||||
<div id="pushDeviceList" class="push-device-list">
|
||||
<div class="spike-log-empty">No push devices.</div>
|
||||
@@ -278,7 +283,7 @@ a{color:inherit;text-decoration:none}
|
||||
</section>
|
||||
</div>
|
||||
<div id="notice" class="notice"></div>
|
||||
<script src="/assets/app.js?v=20260607_nowifibtn1"></script>
|
||||
<script src="/assets/app.js?v=20260607_pushhealth1"></script>
|
||||
<script src="/assets/wakelock.js?v=20260606_wakelock2"></script>
|
||||
<script src="/push_subscribe.js?v=20260606_noappend1"></script>
|
||||
<?php endif; ?>
|
||||
|
||||
Reference in New Issue
Block a user