57 lines
2.1 KiB
PHP
57 lines
2.1 KiB
PHP
<?php
|
|
header("Content-Type: application/json");
|
|
$started = microtime(true);
|
|
|
|
function fj($url, $t=3) {
|
|
$ctx = stream_context_create(["http"=>["timeout"=>$t],"ssl"=>["verify_peer"=>false]]);
|
|
$raw = @file_get_contents($url, false, $ctx);
|
|
return $raw ? json_decode($raw, true) : null;
|
|
}
|
|
|
|
$load = sys_getloadavg();
|
|
$s204 = ["alive"=>true, "host"=>"204.168.152.13", "load_1m"=>round($load[0],2), "load_5m"=>round($load[1],2)];
|
|
|
|
$s95_raw = fj("http://10.1.0.3:5890/api/sentinel-brain.php?action=ping", 3);
|
|
$s95 = ["alive"=>!!$s95_raw, "host"=>"10.1.0.3", "response"=>$s95_raw ? "ok" : "timeout"];
|
|
|
|
$bhb = @json_decode(@file_get_contents("/var/www/html/api/blade-heartbeat.json"), true);
|
|
$bage = 999999;
|
|
if ($bhb && isset($bhb["last_heartbeat_ts_epoch"])) $bage = time() - (int)$bhb["last_heartbeat_ts_epoch"];
|
|
$blade = ["alive"=>$bage<1800, "age_s"=>$bage, "tasks_today"=>$bhb["tasks_today"] ?? 0, "tasks_week"=>$bhb["tasks_week"] ?? 0];
|
|
|
|
$q = @json_decode(@file_get_contents("/var/www/html/api/blade-queue.json"), true);
|
|
if (!is_array($q)) $q = [];
|
|
$qs = ["total"=>count($q), "recent"=>0, "stale"=>0];
|
|
$nt = time();
|
|
foreach ($q as $t) {
|
|
$ts = $t["created_at"] ?? $t["ts"] ?? "";
|
|
if ($ts) {
|
|
$age = $nt - strtotime($ts);
|
|
if ($age < 7200) $qs["recent"]++;
|
|
else $qs["stale"]++;
|
|
}
|
|
}
|
|
|
|
$gpu = ["cerebras","groq","sambanova","nvidia","gemini","together","huggingface","replicate","cohere","openrouter","zhipu"];
|
|
$ok = $s204["alive"] && $s95["alive"] && $blade["alive"];
|
|
|
|
$online = 0;
|
|
if ($s204["alive"]) $online++;
|
|
if ($s95["alive"]) $online++;
|
|
if ($blade["alive"]) $online++;
|
|
$online++;
|
|
|
|
$out = [
|
|
"ok"=>$ok, "v"=>"V9.31-unified", "ts"=>date("c"),
|
|
"duration_ms"=>round((microtime(true)-$started)*1000,1),
|
|
"nodes"=>[
|
|
"wevia_master"=>["alive"=>true, "host"=>"localhost"],
|
|
"s204"=>$s204, "s95"=>$s95, "blade"=>$blade,
|
|
"gpu_free"=>["total"=>count($gpu), "cost_eur"=>0]
|
|
],
|
|
"queue"=>$qs,
|
|
"orchestration"=>["doctrine"=>"#12 WEVIA-FIRST + #7", "workers_online"=>$online, "workers_total"=>4]
|
|
];
|
|
|
|
echo json_encode($out, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
|