38770-vm/healthz.php
2026-02-25 23:26:27 +00:00

39 lines
936 B
PHP

<?php
require_once __DIR__ . '/db/config.php';
header('Content-Type: application/json');
$response = [
'status' => 'healthy',
'timestamp' => date('c'),
'php_version' => PHP_VERSION,
'database' => 'disconnected',
'monitor_engine' => 'offline'
];
try {
if (db()) {
$response['database'] = 'connected';
}
} catch (Exception $e) {
$response['database'] = 'error: ' . $e->getMessage();
}
$lockFile = __DIR__ . '/monitor.lock';
if (file_exists($lockFile)) {
$fp = fopen($lockFile, 'r');
if (!flock($fp, LOCK_EX | LOCK_NB)) {
$response['monitor_engine'] = 'running';
}
fclose($fp);
}
if ($response['status'] === 'healthy' && $response['database'] === 'connected' && $response['monitor_engine'] === 'running') {
http_response_code(200);
} else {
// We don't necessarily want 500 if monitor is just offline
http_response_code(200);
}
echo json_encode($response);