mirror of
https://github.com/myronblair/jarvis
synced 2026-06-30 17:50:23 -05:00
c29d1bf4c7
- Proactive alerts (#1): polls every 60s; baselines on load so old alerts are silent; speaks new critical/warning alerts aloud if voice active; adds chat bubble for all new alerts - Jellyfin control (#2): pause/stop/next/previous via voice — auto-detects active session; 12 KB intents; jellyfin.php control action uses Jellyfin General Commands API - Agent sparklines (#6): metrics.php returns 2h CPU+MEM history per agent; SVG polyline sparklines rendered in each agent card (cyan=CPU, green=MEM); non-blocking fetch so existing view shows instantly - Agent health CCR (#7): updated hourly cloud routine to current 13-agent roster, removed ollama-ai and alien-pc, added all active agents with correct IPs/IDs Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
52 lines
1.8 KiB
PHP
52 lines
1.8 KiB
PHP
<?php
|
|
// Agent metrics history — returns CPU/RAM samples for sparklines
|
|
require_once __DIR__ . '/../config.php';
|
|
require_once __DIR__ . '/../../includes/auth.php';
|
|
header('Content-Type: application/json');
|
|
AuthMiddleware::requireAuth();
|
|
|
|
$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));
|
|
}
|