Strengthen push device health checks

This commit is contained in:
seo
2026-06-07 06:43:17 +09:00
parent 79208784e2
commit 39aa262469
5 changed files with 295 additions and 9 deletions
+44 -4
View File
@@ -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 || {};