Files
html/api/prometheus-api.php
2026-04-12 22:57:03 +02:00

12 lines
549 B
PHP

<?php
header('Content-Type: application/json');
$raw = @file_get_contents('http://localhost:9100/metrics');
$m = [];
if ($raw) {
if (preg_match('/node_load1\s+([\d.]+)/', $raw, $x)) $m['load'] = (float)$x[1];
if (preg_match('/node_memory_MemAvailable_bytes\s+([\d.e+]+)/', $raw, $x)) $m['ram_avail_gb'] = round($x[1]/1073741824,1);
if (preg_match('/node_boot_time_seconds\s+([\d.]+)/', $raw, $x)) $m['uptime_days'] = round((time()-$x[1])/86400,1);
}
$m['server']='S204'; $m['ts']=date('c');
echo json_encode(['ok'=>true,'metrics'=>$m]);