Skip to content

Instalacao

Luiz Kim edited this page Dec 6, 2026 · 1 revision

Instalação

composer require controleonline/healthcheck-sdk

Requer PHP 8.1+ e Guzzle 7. A integração Symfony funciona com Symfony 6.4, 7 e 8.

Variáveis de ambiente (auto-registro)

Variável Exemplo Uso
HEALTHCHECK_MONITORS https://c3po.controleonline.com,https://r2d2.controleonline.com Monitores onde se registrar.
HEALTHCHECK_TOKEN (segredo) Token de registro do cliente, gerado no admin do monitor. Só em .env.local/secrets.
HEALTHCHECK_URL https://api.controleonline.com/health URL pública do healthcheck desta aplicação.
HEALTHCHECK_CLIENT controleonline Identificador do cliente (empresa) no monitor.
HEALTHCHECK_NAME API produção Nome exibido (padrão: host da URL).
HEALTHCHECK_VERSION 1.2.3 Versão exibida no healthcheck.
HEALTHCHECK_ENVIRONMENT production Opcional.

Sem HEALTHCHECK_MONITORS/TOKEN/URL/CLIENT, o healthcheck funciona normalmente e o registro é ignorado.

Symfony

// config/bundles.php
ControleOnline\Healthcheck\Bridge\Symfony\HealthcheckBundle::class => ['all' => true],
# config/routes/healthcheck.yaml
healthcheck:
    resource: '@HealthcheckBundle/config/routes.php'   # GET|HEAD /health

# config/packages/healthcheck.yaml (tudo opcional)
healthcheck:
    version: '%env(default::HEALTHCHECK_VERSION)%'
    metrics: true                    # memória, CPU (load) e disco quando der para ler
    doctrine_connections: [default]  # SELECT 1 em cada conexão (check crítico "database")
    register_on_terminate: true      # auto-registro depois da resposta, quando devido

Libere ^/health no firewall (PUBLIC_ACCESS). Checks próprios: serviços que implementam ControleOnline\Healthcheck\Check\CheckInterface entram sozinhos (autoconfigure). Comando: bin/console healthcheck:register [--force].

PHP puro

require 'vendor/autoload.php';

use ControleOnline\Healthcheck\Healthcheck;

(new Healthcheck('1.2.3'))
    ->addCheck('database', fn () => $pdo->query('SELECT 1') !== false)
    ->addCheck('cache', fn () => is_writable(__DIR__ . '/cache'), critical: false)
    ->respond();

Registro: vendor/bin/healthcheck-register [--force] [--state=var/healthcheck-registration.json] (no deploy).

Clone this wiki locally