From 60b88dd4d4202308b5be0a2115019203b1f173b9 Mon Sep 17 00:00:00 2001 From: nate Date: Thu, 9 Apr 2026 23:53:02 +0400 Subject: [PATCH] store more metadata --- apps/api/src/routes/pings.ts | 7 +++++-- apps/monitor/src/runner.rs | 2 ++ apps/monitor/src/types.rs | 1 + apps/shared/db.ts | 4 +++- apps/web/src/views/detail.ejs | 2 ++ 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/apps/api/src/routes/pings.ts b/apps/api/src/routes/pings.ts index dd807e3..dfa060d 100644 --- a/apps/api/src/routes/pings.ts +++ b/apps/api/src/routes/pings.ts @@ -132,7 +132,7 @@ export const ingest = new Elysia() `; const [ping] = await sql` - INSERT INTO pings (monitor_id, checked_at, scheduled_at, jitter_ms, status_code, latency_ms, up, important, error, meta, region, run_id, cert_expiry_days) + INSERT INTO pings (monitor_id, checked_at, scheduled_at, jitter_ms, status_code, latency_ms, up, important, error, meta, region, run_id, cert_expiry_days, cert_issuer, response_size) VALUES ( ${body.monitor_id}, ${checkedAt ?? sql`now()`}, @@ -146,7 +146,9 @@ export const ingest = new Elysia() ${Object.keys(meta).length > 0 ? sql.json(meta) : null}, ${region}, ${body.run_id ?? null}, - ${body.cert_expiry_days ?? null} + ${body.cert_expiry_days ?? null}, + ${body.cert_issuer ?? null}, + ${body.response_size ?? null} ) RETURNING * `; @@ -197,6 +199,7 @@ export const ingest = new Elysia() error: t.Optional(t.Nullable(t.String())), cert_expiry_days: t.Optional(t.Nullable(t.Number())), cert_issuer: t.Optional(t.Nullable(t.String())), + response_size: t.Optional(t.Nullable(t.Number())), meta: t.Optional(t.Any()), region: t.Optional(t.Nullable(t.String())), run_id: t.Optional(t.Nullable(t.String())), diff --git a/apps/monitor/src/runner.rs b/apps/monitor/src/runner.rs index a743d30..c32eeb0 100644 --- a/apps/monitor/src/runner.rs +++ b/apps/monitor/src/runner.rs @@ -106,6 +106,7 @@ pub async fn fetch_and_run( error: Some(format!("timed out after {}ms", timeout_ms)), cert_expiry_days: None, cert_issuer: None, + response_size: None, meta: None, region: Some(region_owned.to_string()), run_id: Some(run_id_owned.clone()), @@ -271,6 +272,7 @@ async fn run_check(client: &reqwest::Client, monitor: &Monitor, scheduled_at: Op error: query_error, cert_expiry_days, cert_issuer, + response_size: Some(body.len()), meta: Some(meta), region: Some(region.to_string()), run_id: Some(run_id.to_string()), diff --git a/apps/monitor/src/types.rs b/apps/monitor/src/types.rs index 1ce1c74..8b27535 100644 --- a/apps/monitor/src/types.rs +++ b/apps/monitor/src/types.rs @@ -50,6 +50,7 @@ pub struct PingResult { pub error: Option, pub cert_expiry_days: Option, pub cert_issuer: Option, + pub response_size: Option, pub meta: Option, pub region: Option, pub run_id: Option, diff --git a/apps/shared/db.ts b/apps/shared/db.ts index e30e908..89dde2a 100644 --- a/apps/shared/db.ts +++ b/apps/shared/db.ts @@ -60,7 +60,9 @@ export async function migrate(sql: any) { meta JSONB, region TEXT NOT NULL DEFAULT 'default', run_id TEXT, - cert_expiry_days INTEGER + cert_expiry_days INTEGER, + cert_issuer TEXT, + response_size INTEGER ) `; await sql`CREATE INDEX IF NOT EXISTS idx_pings_monitor ON pings(monitor_id, checked_at DESC)`; diff --git a/apps/web/src/views/detail.ejs b/apps/web/src/views/detail.ejs index ccb2aaf..de01db0 100644 --- a/apps/web/src/views/detail.ejs +++ b/apps/web/src/views/detail.ejs @@ -371,6 +371,8 @@ if (ping.region) html += `
Region
${escapeHtml(ping.region)}
`; if (ping.run_id) html += `
Run ID
${escapeHtml(ping.run_id)}
`; if (ping.cert_expiry_days != null) html += `
Cert expiry
${ping.cert_expiry_days} days
`; + if (ping.cert_issuer) html += `
Cert issuer
${escapeHtml(ping.cert_issuer)}
`; + if (ping.response_size != null) html += `
Response size
${ping.response_size >= 1024 ? (ping.response_size / 1024).toFixed(1) + ' KB' : ping.response_size + ' B'}
`; html += ''; // Error