Server: HTML dashboard at /dashboard showing all sites + session history

Browsable at /dashboard — authenticates via ?key=<api_key> once per browser
session (stored in a PHP session cookie). Lists all sites ordered by most-
recently-active, with session counts and in-progress badge. Click any site
to see its full healthcheck history with dates and durations.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-07-10 09:01:05 +01:00
parent 3d67b94896
commit 9f13d871bf
3 changed files with 257 additions and 0 deletions

View File

@@ -176,4 +176,42 @@ final class Store {
$rows = $stmt->fetchAll();
return array_map(static fn($r) => ['site_key' => $r['site_key'], 'last_seen' => (int) $r['last_seen']], $rows);
}
/**
* Summary of all sites for the dashboard: one row per site_key,
* ordered by most-recently-active first.
* @return array<int, array{site_key:string, total:int, finished:int, last_started_at:int, last_finished_at:int|null, last_reporting_url:string}>
*/
public static function allSitesSummary(): array {
$stmt = Db::pdo()->query(
'SELECT
site_key,
COUNT(*) AS total,
SUM(CASE WHEN finished_at IS NOT NULL THEN 1 ELSE 0 END) AS finished,
MAX(started_at) AS last_started_at
FROM healthchecks
GROUP BY site_key
ORDER BY MAX(updated_at) DESC'
);
$rows = $stmt->fetchAll();
// Fetch the reporting_url and finished_at from the most recent session per site.
$out = [];
foreach ($rows as $r) {
$detail = Db::pdo()->prepare(
'SELECT reporting_url, finished_at FROM healthchecks
WHERE site_key = ? ORDER BY started_at DESC LIMIT 1'
);
$detail->execute([$r['site_key']]);
$last = $detail->fetch() ?: [];
$out[] = [
'site_key' => (string) $r['site_key'],
'total' => (int) $r['total'],
'finished' => (int) $r['finished'],
'last_started_at' => (int) $r['last_started_at'],
'last_finished_at' => isset($last['finished_at']) && $last['finished_at'] !== null ? (int) $last['finished_at'] : null,
'last_reporting_url' => (string) ($last['reporting_url'] ?? ''),
];
}
return $out;
}
}