Files
news-platform/docs/monitoring.md
Artur Moreira 013bdca8f3 docs: incident runbook for aggregator stall, lag, escalation (BIT-3915)
Add NEWS_PLATFORM_INCIDENT_RUNBOOK_BIT3915 with detection/recovery for the
writer-pipeline HTTP aggregator, lag signals, and escalation ladder. Cross-link
from monitoring, aggregator operations, and the runbooks index.

Made-with: Cursor
2026-04-17 04:01:17 +00:00

6.3 KiB

Service Health Monitoring

Automated health monitoring and alerting for the news-platform services on CT 222 (news-project-test, 10.10.50.140).
BIT-746 adds a must-not-fail inventory, optional public URL probing, optional bridge deep checks, and an escalation runbook: docs/runbooks/NEWS_PLATFORM_MONITORING_ALERTS_BIT746.md.
BIT-3915 adds pipeline incident coverage (aggregator stall, lag signals, escalation): docs/runbooks/NEWS_PLATFORM_INCIDENT_RUNBOOK_BIT3915.md.
Runbook index: docs/runbooks/README.md (links deployment, smoke script, and company-wide paperclip runbooks).

Fleet-wide LXC context (confirm on metal): paperclip repo docs/environments/03-lxc.md.

Architecture

┌─────────────────────────┐
│   systemd timer (3 min) │
│  news-healthcheck.timer │
└───────────┬─────────────┘
            │
            ▼
┌─────────────────────────┐     ┌──────────────┐
│    healthcheck.sh       │────▶│  Ntfy Server  │
│  (HTTP probes + systemd │     │  (push alert) │
│   restart detection)    │     └──────────────┘
└───────────┬─────────────┘
            │ checks
            ▼
    ┌────────────────────┐
    │ bridge :3200       │  GET /health (+ optional ?checks=true)
    │ frontend :4321     │  GET /health.json
    │ wordpress :8080    │  GET /wp-json/wp/v2/
    │ optional HTTPS URL │  GET customer page (e.g. /noticias)
    │ systemd units      │  is-active + NRestarts
    └────────────────────┘

┌─────────────────────────┐
│  systemd OnFailure=     │     ┌──────────────┐
│  [email protected]    │────▶│  Ntfy Server  │
│  (instant crash alert)  │     │  (urgent)     │
└─────────────────────────┘     └──────────────┘

Components

Health Endpoints

Service Endpoint Notes
Bridge GET /health Basic liveness (status, timestamp, uptime)
Bridge GET /health?checks=true Deep check — probes WordPress + Redis
Frontend GET /health.json Basic liveness (status, timestamp, uptime)
WordPress GET /wp-json/wp/v2/ Standard WP REST API probe
Public page (optional) Customer https://… URL BIT-746 — NPM/TLS/SSR path; curl 20 s, follows redirects
Bridge deep (optional) GET /health?checks=true WordPress + Redis via bridge (heavier)

Must-not-fail summary (MVP)

Check name Interval HTTP timeout Notes
Timer cadence 3 min — OnUnitActiveSec=180, AccuracySec=30
Local HTTP same 10 s bridge, frontend, wordpress, optional deep
Public page same 20 s only if PUBLIC_PAGE_URL is set
systemd same n/a news-bridge, news-frontend, news-wordpress

State and history: journalctl -u news-healthcheck (and -u news-alert@… for instant crash alerts).

Monitoring Script (deploy/scripts/healthcheck.sh)

Checks all three services via HTTP and verifies systemd unit status. Features:

  • HTTP probes — bridge, frontend, WordPress; optional bridge deep and public URL
  • Restart detection — alerts when systemd NRestarts exceeds threshold (catches crash loops like BIT-743)
  • Ntfy alerting — sends push notifications to a self-hosted Ntfy topic
  • Cooldown logic — suppresses repeat alerts for the same failure pattern (default: 15 min)

systemd Timer (news-healthcheck.timer)

Runs healthcheck.sh every 3 minutes (detection within 5 minutes guaranteed).

OnFailure Alerts ([email protected])

Template unit triggered immediately when any service unit fails. Sends an urgent priority notification to Ntfy with the failed service name and timestamp.

Configuration

Edit /etc/news-platform/healthcheck.env on the LXC:

# Required: Ntfy topic URL
NTFY_URL=https://ntfy.bitreport.pt/news-alerts

# Optional: auth token for private Ntfy topics
NTFY_TOKEN=

# Defaults (usually fine for CT222)
BRIDGE_URL=http://127.0.0.1:3200/health
# Optional deep check (WordPress + Redis through bridge)
# BRIDGE_DEEP_URL=http://127.0.0.1:3200/health?checks=true
FRONTEND_URL=http://127.0.0.1:4321/health.json
WP_URL=http://127.0.0.1:8080/wp-json/wp/v2/
# Strongly recommended for production customer sites (BIT-746)
# PUBLIC_PAGE_URL=https://andebol.net/noticias

# Alert when NRestarts exceeds this
RESTART_THRESHOLD=10

# Seconds between repeat alerts for same failure
COOLDOWN_SECS=900

Deployment

The deploy.sh script automatically installs and enables the monitoring units. For manual setup:

# Install units
cp deploy/systemd/news-healthcheck.service /etc/systemd/system/
cp deploy/systemd/news-healthcheck.timer /etc/systemd/system/
cp deploy/systemd/[email protected] /etc/systemd/system/

# Create env file
cp deploy/systemd/healthcheck.env.example /etc/news-platform/healthcheck.env
# Edit NTFY_URL in the env file

# Enable and start
systemctl daemon-reload
systemctl enable --now news-healthcheck.timer

# Verify
systemctl list-timers news-healthcheck.timer
systemctl status news-healthcheck.timer

Manual Check

# Run health check manually
/opt/news-platform/deploy/scripts/healthcheck.sh

# Check timer status
systemctl list-timers news-healthcheck*

# View recent healthcheck logs
journalctl -u news-healthcheck --since "1 hour ago"

# Test bridge deep health
curl -s http://127.0.0.1:3200/health?checks=true | jq .