diff --git a/apps/monitor/src/runner.rs b/apps/monitor/src/runner.rs index 90d1420..4da5195 100644 --- a/apps/monitor/src/runner.rs +++ b/apps/monitor/src/runner.rs @@ -1,5 +1,5 @@ use crate::query::{self, Response}; -use crate::types::{CheckResult, Monitor}; +use crate::types::{PingResult, Monitor}; use anyhow::Result; use serde_json::json; use std::collections::HashMap; @@ -42,7 +42,7 @@ pub async fn fetch_and_run( Ok(n) } -async fn run_check(client: &reqwest::Client, monitor: &Monitor) -> CheckResult { +async fn run_check(client: &reqwest::Client, monitor: &Monitor) -> PingResult { let start = Instant::now(); // Check cert expiry for HTTPS URLs @@ -56,7 +56,7 @@ async fn run_check(client: &reqwest::Client, monitor: &Monitor) -> CheckResult { let latency_ms = start.elapsed().as_millis() as u64; match result { - Err(e) => CheckResult { + Err(e) => PingResult { monitor_id: monitor.id.clone(), status_code: None, latency_ms: Some(latency_ms), @@ -102,7 +102,7 @@ async fn run_check(client: &reqwest::Client, monitor: &Monitor) -> CheckResult { debug!("{} → {status} {latency_ms}ms up={up}", monitor.url); - CheckResult { + PingResult { monitor_id: monitor.id.clone(), status_code: Some(status), latency_ms: Some(latency_ms), @@ -165,7 +165,7 @@ async fn post_result( client: &reqwest::Client, coordinator_url: &str, token: &str, - result: CheckResult, + result: PingResult, ) -> Result<()> { client .post(format!("{coordinator_url}/internal/ingest")) diff --git a/apps/monitor/src/types.rs b/apps/monitor/src/types.rs index 5f6f505..d44a326 100644 --- a/apps/monitor/src/types.rs +++ b/apps/monitor/src/types.rs @@ -10,7 +10,7 @@ pub struct Monitor { } #[derive(Debug, Serialize)] -pub struct CheckResult { +pub struct PingResult { pub monitor_id: String, pub status_code: Option, pub latency_ms: Option, diff --git a/apps/web/src/dashboard/detail.html b/apps/web/src/dashboard/detail.html index a304740..7401fbe 100644 --- a/apps/web/src/dashboard/detail.html +++ b/apps/web/src/dashboard/detail.html @@ -56,7 +56,7 @@
-
Last Check
+
Last Ping
@@ -73,10 +73,10 @@
- +
-

Recent Checks

+

Recent Pings

@@ -89,7 +89,7 @@ - +
Error
@@ -148,12 +148,12 @@ document.getElementById('content').classList.remove('hidden'); const results = data.results || []; - const lastCheck = results[0]; + const lastPing = results[0]; // Header document.getElementById('monitor-name').textContent = data.name; document.getElementById('monitor-url').textContent = data.url; - document.getElementById('status-dot').innerHTML = statusBadge(lastCheck?.up); + document.getElementById('status-dot').innerHTML = statusBadge(lastPing?.up); // Toggle button const toggleBtn = document.getElementById('toggle-btn'); @@ -166,41 +166,41 @@ // Delete button document.getElementById('delete-btn').onclick = async () => { - if (!confirm('Delete this monitor and all its check history?')) return; + if (!confirm('Delete this monitor and all its ping history?')) return; await api(`/monitors/${monitorId}`, { method: 'DELETE' }); window.location.href = '/dashboard/home'; }; // Stats - const upChecks = results.filter(r => r.up); + const upPings = results.filter(r => r.up); const latencies = results.filter(r => r.latency_ms != null).map(r => r.latency_ms); const avgLatency = latencies.length ? Math.round(latencies.reduce((a, b) => a + b, 0) / latencies.length) : null; - const uptime = results.length ? Math.round((upChecks.length / results.length) * 100) : null; + const uptime = results.length ? Math.round((upPings.length / results.length) * 100) : null; - document.getElementById('stat-status').innerHTML = lastCheck - ? (lastCheck.up ? 'Up' : 'Down') + document.getElementById('stat-status').innerHTML = lastPing + ? (lastPing.up ? 'Up' : 'Down') : ''; document.getElementById('stat-latency').textContent = avgLatency != null ? `${avgLatency}ms` : '—'; document.getElementById('stat-uptime').textContent = uptime != null ? `${uptime}%` : '—'; - document.getElementById('stat-last').textContent = lastCheck ? timeAgo(lastCheck.checked_at) : '—'; + document.getElementById('stat-last').textContent = lastPing ? timeAgo(lastPing.pinged_at) : '—'; // Latency chart renderLatencyChart(results.slice().reverse()); // Status bar const statusBar = document.getElementById('status-bar'); - const barChecks = results.slice(0, 60).reverse(); - statusBar.innerHTML = barChecks.map(c => - `
` + const barPings = results.slice(0, 60).reverse(); + statusBar.innerHTML = barPings.map(c => + `
` ).join('') || '
No data
'; - // Checks table - document.getElementById('checks-table').innerHTML = results.slice(0, 30).map(c => ` + // Pings table + document.getElementById('pings-table').innerHTML = results.slice(0, 30).map(c => ` ${c.up ? 'Up' : 'Down'} ${c.status_code ?? '—'} ${c.latency_ms != null ? c.latency_ms + 'ms' : '—'} - ${timeAgo(c.checked_at)} + ${timeAgo(c.pinged_at)} ${c.error ? escapeHtml(c.error) : ''} `).join(''); @@ -216,9 +216,9 @@ } } - function renderLatencyChart(checks) { + function renderLatencyChart(pings) { const container = document.getElementById('latency-chart'); - const data = checks.filter(c => c.latency_ms != null); + const data = pings.filter(c => c.latency_ms != null); if (data.length < 2) { container.innerHTML = '
Not enough data
'; return; diff --git a/apps/web/src/dashboard/home.html b/apps/web/src/dashboard/home.html index de6edd8..8dbe571 100644 --- a/apps/web/src/dashboard/home.html +++ b/apps/web/src/dashboard/home.html @@ -54,32 +54,32 @@ return; } - // Fetch last check for each monitor - const monitorsWithChecks = await Promise.all( + // Fetch last ping for each monitor + const monitorsWithPings = await Promise.all( monitors.map(async (m) => { try { - const checks = await api(`/monitors/${m.id}/history?limit=20`); - return { ...m, checks }; + const pings = await api(`/monitors/${m.id}/pings?limit=20`); + return { ...m, pings }; } catch { - return { ...m, checks: [] }; + return { ...m, pings: [] }; } }) ); - const upCount = monitorsWithChecks.filter(m => m.checks[0]?.up === true).length; - const downCount = monitorsWithChecks.filter(m => m.checks[0]?.up === false).length; + const upCount = monitorsWithPings.filter(m => m.pings[0]?.up === true).length; + const downCount = monitorsWithPings.filter(m => m.pings[0]?.up === false).length; summary.innerHTML = `${upCount} up · ${downCount} down · ${monitors.length} total`; - list.innerHTML = monitorsWithChecks.map(m => { - const lastCheck = m.checks[0]; - const latencies = m.checks.filter(c => c.latency_ms != null).map(c => c.latency_ms).reverse(); + list.innerHTML = monitorsWithPings.map(m => { + const lastPing = m.pings[0]; + const latencies = m.pings.filter(c => c.latency_ms != null).map(c => c.latency_ms).reverse(); const avgLatency = latencies.length ? Math.round(latencies.reduce((a, b) => a + b, 0) / latencies.length) : null; return `
- ${statusBadge(lastCheck?.up)} + ${statusBadge(lastPing?.up)}
${escapeHtml(m.name)}
${escapeHtml(m.url)}
@@ -89,7 +89,7 @@
${avgLatency != null ? avgLatency + 'ms' : '—'}
-
${lastCheck ? timeAgo(lastCheck.checked_at) : 'no checks'}
+
${lastPing ? timeAgo(lastPing.pinged_at) : 'no pings'}
${m.enabled ? m.interval_s + 's' : 'paused'}
diff --git a/apps/web/src/dashboard/index.html b/apps/web/src/dashboard/index.html index 9e0c76e..534318f 100644 --- a/apps/web/src/dashboard/index.html +++ b/apps/web/src/dashboard/index.html @@ -23,7 +23,7 @@ + maxlength="19" autocomplete="off" spellping="false">
- +