Skip to content

Fase 3.2: Monitoring + Health Checks

← Anterior: 3.1 Retry | Siguiente: 3.3 Systemd →


Crear metrics endpoint

Archivo: */backend/background-jobs-system.md

Rama: feature/background-jobs-monitoring

Fase: 3.2: Monitoring + Health Checks

Estimación: 4 horas

Dependencias: Crear admin endpoint

Deliverables

  • [ ] Crear server/src/controller/modulo-background-jobs/MetricsController.php
    • [ ] GET /jobs/metrics (Prometheus format)
    • [ ] Métricas: jobs_pending, jobs_processing, jobs_completed, jobs_failed, average_execution_time
    • [ ] Por schema
    • [ ] Sin auth (para Prometheus scraping)
  • [ ] Queries optimizadas (agregaciones BD)
  • [ ] Cache 60 segundos
  • [ ] Create routes /jobs/metrics
  • [ ] Tests verificando Prometheus format

Crear health check endpoint

Archivo: */backend/background-jobs-system.md

Rama: feature/background-jobs-monitoring

Fase: 3.2: Monitoring + Health Checks

Estimación: 3 horas

Dependencias: Crear metrics endpoint

Deliverables

  • [ ] Crear server/src/services/BackgroundJobs/HealthChecker.php
    • [ ] Verifica worker process activo
    • [ ] Verifica BD connectivity
    • [ ] Verifica pending jobs queue no > 1000
    • [ ] Retorna status: healthy/degraded/unhealthy
  • [ ] GET /jobs/health endpoint
  • [ ] Response: { status, checks: { worker, database, queue } }
  • [ ] Unit tests
  • [ ] Integration tests

Agregar logging estructurado

Archivo: */backend/background-jobs-system.md

Rama: feature/background-jobs-monitoring

Fase: 3.2: Monitoring + Health Checks

Estimación: 3 horas

Dependencias: Crear health check endpoint

Deliverables

  • [ ] Implementar structured logging en JobRunner
    • [ ] JSON format:
    • [ ] Log a STDOUT y file (var/logs/background-jobs.log)
    • [ ] Log levels: info, warning, error
  • [ ] Logs en JobDispatcher
  • [ ] Logs en JobStreamController
  • [ ] Log rotation (daily, 7 days retention)
  • [ ] Tests verificando log format

Crear alert triggers

Archivo: */backend/background-jobs-system.md

Rama: feature/background-jobs-monitoring

Fase: 3.2: Monitoring + Health Checks

Estimación: 4 horas

Dependencias: Agregar logging estructurado

Deliverables

  • [ ] Crear server/src/services/BackgroundJobs/AlertService.php
    • [ ] Trigger: failed jobs > 5 en 5 minutos
    • [ ] Trigger: pending jobs > 500
    • [ ] Trigger: worker inactivo > 10 minutos
    • [ ] Envía a external alert service (Slack/email webhook)
  • [ ] Configuración en constants (thresholds)
  • [ ] Cronjob verifica triggers cada 5 minutos
  • [ ] Cooldown 30 minutos entre alerts mismo tipo
  • [ ] Unit tests
  • [ ] Integration tests

← Anterior: 3.1 Retry | Siguiente: 3.3 Systemd →