mirror of
https://github.com/myronblair/jarvis
synced 2026-06-30 17:50:23 -05:00
perf: fix facts_collector blocking cron that was saturating PHP workers
Three issues caused periodic worker saturation: 1. Network section pinged 5 private LAN IPs (10.48.200.x) unreachable from DO — each failed after 1s timeout = 5s wasted per run. Replaced with a fast DB query on registered_agents. 2. pve_api_get() had no CURLOPT_CONNECTTIMEOUT — added 3s limit so unreachable Proxmox fails fast instead of blocking the full 8s. 3. Ollama curl timeout reduced from 5s→3s total, added 2s connect limit. Cron interpreter also changed from lsphp85 to php8.3 in crontab (done directly on server) — lsphp85 adds ~8s LSAPI startup overhead and consumes a PHP worker slot; php8.3 runs standalone. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -80,26 +80,15 @@ function collect_all(): array {
|
||||
$results['system'] = 'error: ' . $e->getMessage();
|
||||
}
|
||||
|
||||
// ── Network ───────────────────────────────────────────────────────────
|
||||
// ── Network — read from agent DB (agents push status, DO can't ping LAN IPs) ──
|
||||
try {
|
||||
$watchlist = [
|
||||
'gateway' => '10.48.200.1',
|
||||
'proxmox' => '10.48.200.90',
|
||||
'ollama' => '10.48.200.95',
|
||||
'fusionpbx' => '10.48.200.96',
|
||||
'ha' => '10.48.200.97',
|
||||
'do_server' => '165.22.1.228',
|
||||
];
|
||||
$online = 0;
|
||||
$total = count($watchlist);
|
||||
foreach ($watchlist as $name => $ip) {
|
||||
exec('ping -c1 -W1 ' . escapeshellarg($ip) . ' > /dev/null 2>&1', $o, $code);
|
||||
$up = ($code === 0);
|
||||
if ($up) $online++;
|
||||
KBEngine::storeFact('network', "host_{$name}", $up ? 'online' : 'offline', $ip, $ttl);
|
||||
}
|
||||
KBEngine::storeFact('network', 'online_count', $online, 'local', $ttl);
|
||||
KBEngine::storeFact('network', 'total_count', $total, 'local', $ttl);
|
||||
$rows = JarvisDB::query(
|
||||
"SELECT status FROM registered_agents WHERE last_seen > DATE_SUB(NOW(), INTERVAL 5 MINUTE)"
|
||||
);
|
||||
$online = count(array_filter($rows, fn($r) => $r['status'] === 'online'));
|
||||
$total = count($rows);
|
||||
KBEngine::storeFact('network', 'online_count', $online, 'local', $ttl);
|
||||
KBEngine::storeFact('network', 'total_count', $total, 'local', $ttl);
|
||||
KBEngine::storeFact('network', 'gateway_status', $online > 0 ? 'online' : 'offline', 'local', $ttl);
|
||||
$results['network'] = "ok ({$online}/{$total} online)";
|
||||
} catch (Exception $e) {
|
||||
@@ -160,7 +149,7 @@ function collect_all(): array {
|
||||
} else try {
|
||||
$ollamaHost = defined('OLLAMA_HOST') ? OLLAMA_HOST : 'http://10.48.200.95:11434';
|
||||
$ch = curl_init($ollamaHost . '/api/tags');
|
||||
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 5]);
|
||||
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_CONNECTTIMEOUT => 2, CURLOPT_TIMEOUT => 3]);
|
||||
$resp = curl_exec($ch);
|
||||
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
@@ -210,6 +199,7 @@ function collect_all(): array {
|
||||
$ch = curl_init($localUrl);
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_CONNECTTIMEOUT => 3,
|
||||
CURLOPT_FOLLOWLOCATION => true,
|
||||
CURLOPT_TIMEOUT => 10,
|
||||
CURLOPT_CONNECTTIMEOUT => 5,
|
||||
@@ -240,9 +230,10 @@ function pve_api_get(string $url, string $authHeader): array {
|
||||
$ch = curl_init($url);
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_CONNECTTIMEOUT => 3,
|
||||
CURLOPT_HTTPHEADER => [$authHeader],
|
||||
CURLOPT_SSL_VERIFYPEER => false,
|
||||
CURLOPT_TIMEOUT => 8,
|
||||
CURLOPT_TIMEOUT => 5,
|
||||
]);
|
||||
$resp = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
Reference in New Issue
Block a user