Adopt live production state as git baseline

This commit is contained in:
root
2026-07-07 07:55:47 -05:00
commit 588cfe3f10
85 changed files with 30896 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
<?php
// Agent metrics history — returns CPU/RAM samples for sparklines
require_once __DIR__ . '/../config.php';
header('Content-Type: application/json');
$agentId = $_GET['agent_id'] ?? '';
$hours = min((int)($_GET['hours'] ?? 2), 24);
if (!$agentId) {
// Return all online agents' last 2h in one shot
$agents = JarvisDB::query(
"SELECT DISTINCT agent_id FROM agent_metrics WHERE recorded_at > DATE_SUB(NOW(), INTERVAL ? HOUR)",
[$hours]
) ?? [];
$out = [];
foreach ($agents as $a) {
$rows = JarvisDB::query(
"SELECT CAST(JSON_EXTRACT(metric_data, '$.cpu_percent') AS DECIMAL(5,1)) as cpu,
CAST(JSON_EXTRACT(metric_data, '$.memory.percent') AS DECIMAL(5,1)) as mem,
recorded_at
FROM agent_metrics
WHERE agent_id = ? AND recorded_at > DATE_SUB(NOW(), INTERVAL ? HOUR)
ORDER BY recorded_at ASC",
[$a['agent_id'], $hours]
) ?? [];
if ($rows) {
$out[$a['agent_id']] = array_map(fn($r) => [
'cpu' => (float)($r['cpu'] ?? 0),
'mem' => (float)($r['mem'] ?? 0),
], $rows);
}
}
echo json_encode($out);
} else {
$rows = JarvisDB::query(
"SELECT CAST(JSON_EXTRACT(metric_data, '$.cpu_percent') AS DECIMAL(5,1)) as cpu,
CAST(JSON_EXTRACT(metric_data, '$.memory.percent') AS DECIMAL(5,1)) as mem,
recorded_at
FROM agent_metrics
WHERE agent_id = ? AND recorded_at > DATE_SUB(NOW(), INTERVAL ? HOUR)
ORDER BY recorded_at ASC",
[$agentId, $hours]
) ?? [];
echo json_encode(array_map(fn($r) => [
'cpu' => (float)($r['cpu'] ?? 0),
'mem' => (float)($r['mem'] ?? 0),
], $rows));
}