ключ проблемы => что случилось */ public static function check(bool $notify = true): array { $problems = []; $queue = Queue::stats(); $failed = (int) ($queue['failed'] ?? 0); $queued = (int) ($queue['queued'] ?? 0); if ($failed >= (int) Config::get('monitor.failed_jobs', 10)) { $problems['queue.failed'] = 'Задач с ошибкой в очереди: ' . $failed; } if ($queued >= (int) Config::get('monitor.queue_backlog', 500)) { $problems['queue.backlog'] = 'Очередь не разбирается, ждёт задач: ' . $queued; } $requests = Metrics::requests(1); if ($requests['errors'] >= (int) Config::get('monitor.errors', 20)) { $problems['http.errors'] = 'Ошибок 5xx за час: ' . $requests['errors']; } $free = (int) (Metrics::storage()['free_bytes'] ?? 0); $limit = (int) Config::get('monitor.free_bytes', 500 * 1024 * 1024); if ($free > 0 && $free < $limit) { $problems['disk.free'] = 'На диске осталось ' . Str::bytes($free); } if ($notify) { foreach ($problems as $key => $message) { self::announce($key, $message); } } return $problems; } /** * Сообщить о проблеме, если о ней давно не говорили. */ private static function announce(string $key, string $message): void { $repeat = max(1, (int) Config::get('monitor.repeat_minutes', 60)) * 60; $last = (int) Setting::get(self::MARK . $key, '0'); if (time() - $last < $repeat) { return; } Setting::set(self::MARK . $key, (string) time()); try { Notify::toPermission(Permission::SYSTEM_MANAGE, new HealthAlertNotification($key, $message)); } catch (Throwable $e) { (new Logger('monitor'))->error('Не удалось разослать предупреждение', [ 'problem' => $key, 'error' => $e->getMessage(), ]); } } }