<?php if (!defined('DASHBOARD_ROOT')) { http_response_code(403); exit; } $nodes = Database::fetchAll("SELECT id,node_id,hostname,wg_ip,status_code,last_heartbeat,metrics FROM nodes ORDER BY hostname"); $now = time(); ?> <div id="heartbeat-monitor" class="panel"> <span class="section-label">Node Heartbeats</span><?php foreach ($nodes as $n): $hb = $n['last_heartbeat'] ? strtotime($n['last_heartbeat']) : 0; $age = $hb > 0 ? ($now - $hb) : PHP_INT_MAX; $ageLabel = $hb > 0 ? round($age/60) . 'm ago' : 'Never'; $healthClass = $age < 120 ? 'success' : ($age < 600 ? 'warning' : 'danger'); $metrics = $n['metrics'] ? json_decode($n['metrics'], true) : []; ?> <div id="hb-<?= UI::e($n['node_id']) ?> " class="event-row"> <span><?= UI::e($n['hostname']) ?> (<?= UI::e($n['wg_ip']??'') ?> )</span> <span><?= StatusCode::render((int)$n['status_code']) ?> </span> <span class="badge badge-<?= $healthClass ?> "><?= $ageLabel ?> </span><?php if (isset($metrics['cpu'])): ?> <span>CPU:<?= (int)$metrics['cpu'] ?> %</span> <span>RAM:<?= (int)$metrics['ram'] ?> %</span><?php endif; ?> </div><?php endforeach; ?> </div>