Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

API Health Monitor

An API health monitoring service in Rust. Users register endpoints to monitor; a background scheduler checks them on their own intervals, records latency and status history, and sends webhook alerts when an endpoint's health status changes.

Stack: Rust · Axum · SQLx · PostgreSQL · Tokio · reqwest · JWT

How it works

A background task ticks every 5 seconds and queries the database for endpoints that are due for a check. This is computed in SQL by comparing each endpoint's last check time plus its check_interval_seconds against now(). Due endpoints are checked concurrently (5 at a time), each result is written to health_check, and if an endpoint's status changed since the last check, the user's active webhooks are notified.

Health statuses: Healthy (2xx response), Unhealthy (non-2xx response), Down (unreachable).

Setup

Requires Rust, PostgreSQL, and sqlx-cli.

cp .env.example .env     # set DATABASE_URL and JWT_SECRET
sqlx database create
sqlx migrate run         # required — migrations don't run automatically
cargo run

Server listens on 0.0.0.0:3000.

API

All routes except /register and /login require Authorization: Bearer <token>. Tokens expire after 1 hour.

Method Path Description
POST /register Create account — { email, password } (min 8 chars)
POST /login Get JWT — { email, password }
POST /endpoints Add endpoint to monitor
GET /endpoints List your endpoints
GET /endpoints/{id} Get one endpoint
PUT /endpoints/{id} Update endpoint (any subset of fields)
DELETE /endpoints/{id} Delete endpoint
GET /endpoints/{id}/history Check history for an endpoint
POST /webhooks Add webhook — { target_url, is_active? }
GET /webhooks List your webhooks
GET /webhooks/{id} Get one webhook
PUT /webhooks/{id} Update webhook
DELETE /webhooks/{id} Delete webhook

Creating an endpoint:

{
  "name": "My API",
  "url": "https://api.example.com/health",
  "check_interval_seconds": 60,
  "expected_status_code": 200,
  "is_active": true
}

name and url are required; the rest default to 60, 200, and true.

Webhook payload

Sent to every active webhook you own whenever one of your endpoints changes status (including its first check):

{
  "url": "https://api.example.com/health",
  "name": "My API",
  "status": 500,
  "health_status": "Unhealthy",
  "error_message": "Returned error code: 500 Internal Server Error"
}

status is 0 if the endpoint was unreachable; error_message is null when healthy.

About

SaaS backend for API health monitoring, written in Rust (Axum + Postgres) with concurrent background health checks, per-endpoint scheduling, and webhook alerts on status changes.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages