<?php
declare(strict_types=1);
require_once __DIR__ . '/../vendor/autoload.php';

use ServerManager\Core\App;
use ServerManager\Services\MonitoringService;

try {
    $app = App::getInstance();
    $app->boot(dirname(__DIR__));

    $monitoring = new MonitoringService();
    $results = $monitoring->collectAllMetrics();

    $online = count(array_filter($results, fn($r) => $r && ($r['status'] ?? '') === 'online'));
    $offline = count($results) - $online;

    echo sprintf("[%s] Metrics collected: %d servers (%d online, %d offline)\n",
        date('Y-m-d H:i:s'), count($results), $online, $offline);
} catch (\Throwable $e) {
    echo sprintf("[%s] ERROR: %s\n", date('Y-m-d H:i:s'), $e->getMessage());
    exit(1);
}
