mirror of
https://github.com/myronblair/jarvis
synced 2026-06-30 17:50:23 -05:00
b7aea1371c
- /api/do now includes do_server key with jarvis-do agent metrics (CPU, RAM, disk, uptime from Tailscale-connected DO server agent) - Front page JARVIS SERVER panel has WEB HOST section with live CPU/RAM/DISK bars from DO server agent data - Panel title updated to show 10.48.200.211 (JARVIS VM IP) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
95 lines
3.3 KiB
PHP
95 lines
3.3 KiB
PHP
<?php
|
|
// Digital Ocean server monitoring — read local /proc directly (no SSH loopback)
|
|
|
|
// CPU usage (sample over 200ms)
|
|
function getCpuPct(): float {
|
|
$s1 = file_get_contents("/proc/stat");
|
|
usleep(200000);
|
|
$s2 = file_get_contents("/proc/stat");
|
|
preg_match("/^cpu\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/m", $s1, $m1);
|
|
preg_match("/^cpu\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/m", $s2, $m2);
|
|
$idle1 = $m1[4]; $total1 = $m1[1]+$m1[2]+$m1[3]+$m1[4];
|
|
$idle2 = $m2[4]; $total2 = $m2[1]+$m2[2]+$m2[3]+$m2[4];
|
|
$dt = $total2 - $total1;
|
|
return $dt > 0 ? round((1 - ($idle2 - $idle1) / $dt) * 100, 1) : 0;
|
|
}
|
|
|
|
$memLines = [];
|
|
foreach (file("/proc/meminfo") as $l) {
|
|
[$k, $v] = explode(":", $l, 2) + [null, null];
|
|
if ($k) $memLines[trim($k)] = (int)trim($v);
|
|
}
|
|
$memTotal = $memLines["MemTotal"] ?? 0;
|
|
$memFree = $memLines["MemAvailable"] ?? 0;
|
|
$memUsed = $memTotal - $memFree;
|
|
|
|
$uptime = (int)explode(" ", file_get_contents("/proc/uptime"))[0];
|
|
$load = (float)explode(" ", file_get_contents("/proc/loadavg"))[0];
|
|
|
|
$dfOut = shell_exec("df / | tail -1 | awk {print }") ?? "";
|
|
$diskPct = trim($dfOut);
|
|
|
|
// Services
|
|
$svcNames = ["nginx", "php8.3-fpm", "mariadb", "redis-server", "jarvis-arc", "jarvis-agent"];
|
|
$svcMap = [];
|
|
foreach ($svcNames as $s) {
|
|
$status = trim(shell_exec("systemctl is-active " . escapeshellarg($s) . " 2>/dev/null") ?? "");
|
|
if ($status === "active") $svcMap[$s] = true;
|
|
}
|
|
|
|
// Site health from kb_facts
|
|
$siteLabels = [
|
|
"jarvis" => "jarvis.orbishosting.com:1972",
|
|
"tomsjavajive" => "tomsjavajive.com",
|
|
"epictravelexp"=> "epictravelexpeditions.com",
|
|
"parkersling" => "parkerslingshotrentals.com",
|
|
"orbishosting" => "orbishosting.com",
|
|
"orbisportal" => "orbis.orbishosting.com",
|
|
"tomtomgames" => "tomtomgames.com",
|
|
];
|
|
$sites = [];
|
|
$rows = JarvisDB::query(
|
|
"SELECT fact_key, fact_value FROM kb_facts WHERE category='sites' AND updated_at > DATE_SUB(NOW(), INTERVAL 15 MINUTE) ORDER BY fact_key"
|
|
);
|
|
foreach ($rows as $r) {
|
|
$label = $siteLabels[$r["fact_key"]] ?? $r["fact_key"];
|
|
$sites[$label] = $r["fact_value"];
|
|
}
|
|
|
|
$uptimeDays = intdiv($uptime, 86400);
|
|
$uptimeHrs = intdiv($uptime % 86400, 3600);
|
|
|
|
|
|
// DO server agent metrics (jarvis-do agent reporting via Tailscale)
|
|
$doAgent = JarvisDB::query(
|
|
"SELECT metric_data FROM agent_metrics WHERE agent_id='jarvis-do_orbis' AND metric_type='system' ORDER BY recorded_at DESC LIMIT 1"
|
|
);
|
|
$doMet = [];
|
|
if (!empty($doAgent[0]['metric_data'])) {
|
|
$dm = json_decode($doAgent[0]['metric_data'], true) ?? [];
|
|
$doMet = [
|
|
"cpu" => $dm['cpu_percent'] ?? 0,
|
|
"mem" => $dm['memory']['percent'] ?? 0,
|
|
"disk" => (int)($dm['disk'][0]['percent'] ?? 0),
|
|
"uptime" => $dm['uptime']['human'] ?? "--",
|
|
"online" => true,
|
|
];
|
|
}
|
|
echo json_encode([
|
|
"ip" => "10.48.200.211", // JARVIS VM (PVE1)
|
|
"reachable" => true,
|
|
"cpu_pct" => getCpuPct(),
|
|
"memory" => [
|
|
"total_mb" => round($memTotal / 1024),
|
|
"used_mb" => round($memUsed / 1024),
|
|
"percent" => $memTotal > 0 ? round(($memUsed / $memTotal) * 100, 1) : 0,
|
|
],
|
|
"disk_used_pct" => $diskPct,
|
|
"load_1m" => $load,
|
|
"uptime" => "{$uptimeDays}d {$uptimeHrs}h",
|
|
"services" => $svcMap,
|
|
"sites" => $sites,
|
|
"do_server" => $doMet,
|
|
"timestamp" => date("c"),
|
|
]);
|