Files
html/api/opus5-s95-health.php
2026-04-17 14:35:01 +02:00

34 lines
1.2 KiB
PHP

<?php
// OPUS5 S95 Health - lightweight wrapper
header('Content-Type: application/json');
$R = ['ts'=>date('c'), 'source'=>'opus5-s95-health'];
$start = microtime(true);
$ch = curl_init('https://10.1.0.3:8443/api/sentinel-brain.php?action=exec&cmd=uptime');
curl_setopt_array($ch, [
CURLOPT_USERPWD => 'weval:W3valAdmin2026',
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 8
]);
$resp = curl_exec($ch);
$http = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$R['http'] = $http;
$R['ms'] = round((microtime(true) - $start) * 1000);
if ($http === 200) {
$d = @json_decode($resp, true);
$R['output'] = trim((string)($d['output'] ?? $resp));
// Extract load averages
if (preg_match('/load average:\s+([\d.]+),\s*([\d.]+),\s*([\d.]+)/', $R['output'], $m)) {
$R['load'] = ['1m' => (float)$m[1], '5m' => (float)$m[2], '15m' => (float)$m[3]];
$R['health'] = $R['load']['1m'] < 10 ? 'OK' : ($R['load']['1m'] < 20 ? 'ELEVATED' : 'CRITICAL');
}
} else {
$R['error'] = 'upstream_' . $http;
}
echo json_encode($R, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);