Skip to content

Rodion5758/MonitorManager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Monitor Manager

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.

Stack

  • Go
  • Chi router
  • net/http
  • PostgreSQL
  • pgx / pgxpool
  • godotenv
  • Docker / Docker Compose
  • SQL migrations

Project structure

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

Run

docker compose up -d --build

This starts PostgreSQL on 5432 and the API on 2433.

Stop

docker compose down
docker compose down -v

Environment

The app reads .env if present and uses these variables:

  • PORT
  • DATABASE_URL

Docker Compose already sets:

PORT=2433
DATABASE_URL=postgres://admin:password@db:5432/monitor_db?sslmode=disable

Migrations

Migrations are plain SQL files in migrations/ and have to be run manually with golang-migrate.

migrate -path migrations -database "$DATABASE_URL" up

Files:

  • 000001_creat_monitors_table — create monitors
  • 000002_add_timeout_to_monitors_table — add timeout_seconds
  • 000003_add_created_at_updated_at_to_monitors — add timestamps
  • 000004_remove_timeout_default_value — drop timeout default
  • 000005_create_check_results_table — create check_results
  • 000006_add_last_checked_at_to_monitors_table — add last_checked_at
  • 000007_add_cascade_to_check_results — add ON DELETE CASCADE

API

Monitors

  • POST /monitors
  • GET /monitors
  • GET /monitors/{id}
  • PUT /monitors/{id}
  • DELETE /monitors/{id}

Checks

  • POST /monitors/{id}/check — run a manual check
  • GET /monitors/{id}/check — get check history

Health

  • GET /healthz

The history route is singular in code: /check, not /checks.

Request shapes

Create monitor

{
  "name": "Google",
  "url": "https://google.com",
  "timeout_seconds": 5,
  "interval_seconds": 30,
  "active": true
}
  • active is optional and defaults to true
  • timeout_seconds and interval_seconds must be positive

Update monitor

{
  "name": "Google",
  "url": "https://google.com",
  "timeout_seconds": 5,
  "interval_seconds": 30
}

Background worker

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.

About

Monitor Manager is a backend service for HTTP uptime monitoring

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors