Monitor Manager is a backend service for HTTP uptime monitoring. It supports monitor CRUD, manual checks, check history in PostgreSQL, and a background worker for active monitors.
- Go
- Chi router
net/http- PostgreSQL
pgx / pgxpoolgodotenv- Docker / Docker Compose
- SQL migrations
cmd/api/ entrypoint
internal/configuration/ env loading
internal/database/ pgx pool setup
internal/httputil/ JSON and response helpers
internal/monitor/ monitor DTOs, handlers, service, repository
internal/monitor/checker/ HTTP checker and check result types
internal/worker/ background worker
migrations/ SQL migrations
docker compose up -d --buildThis starts PostgreSQL on 5432 and the API on 2433.
docker compose down
docker compose down -vThe app reads .env if present and uses these variables:
PORTDATABASE_URL
Docker Compose already sets:
PORT=2433
DATABASE_URL=postgres://admin:password@db:5432/monitor_db?sslmode=disableMigrations are plain SQL files in migrations/ and have to be run manually with golang-migrate.
migrate -path migrations -database "$DATABASE_URL" upFiles:
000001_creat_monitors_table— createmonitors000002_add_timeout_to_monitors_table— addtimeout_seconds000003_add_created_at_updated_at_to_monitors— add timestamps000004_remove_timeout_default_value— drop timeout default000005_create_check_results_table— createcheck_results000006_add_last_checked_at_to_monitors_table— addlast_checked_at000007_add_cascade_to_check_results— addON DELETE CASCADE
POST /monitorsGET /monitorsGET /monitors/{id}PUT /monitors/{id}DELETE /monitors/{id}
POST /monitors/{id}/check— run a manual checkGET /monitors/{id}/check— get check history
GET /healthz
The history route is singular in code:
/check, not/checks.
{
"name": "Google",
"url": "https://google.com",
"timeout_seconds": 5,
"interval_seconds": 30,
"active": true
}activeis optional and defaults totruetimeout_secondsandinterval_secondsmust be positive
{
"name": "Google",
"url": "https://google.com",
"timeout_seconds": 5,
"interval_seconds": 30
}The worker polls every 2 seconds, finds active due monitors, and runs checks in goroutines. It updates last_checked_at after saving a check result.