aboutsummaryrefslogtreecommitdiff
path: root/api/debug/health.php
blob: 5a0048fa2564cca6dbd2eb204bcf97463779a6b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
require_once __DIR__ . '/config.php';

$errors = load_json(ERRORS_FILE);
$sessions = load_json(SESSIONS_FILE);

$lastError = !empty($errors) ? end($errors) : null;

json_response([
    'success' => true,
    'status' => 'ok',
    'uptime' => filemtime(__FILE__) ? (time() - filemtime(__FILE__)) : 0,
    'total_errors' => count($errors),
    'total_sessions' => count($sessions),
    'errors_file_size_kb' => file_exists(ERRORS_FILE) ? round(filesize(ERRORS_FILE) / 1024, 1) : 0,
    'sessions_file_size_kb' => file_exists(SESSIONS_FILE) ? round(filesize(SESSIONS_FILE) / 1024, 1) : 0,
    'last_ingest' => $lastError ? ($lastError['ingested_at'] ?? null) : null,
    'last_ingest_message' => $lastError ? substr($lastError['message'] ?? '', 0, 100) : null,
    'generated_at' => date('c'),
]);