Automated Action 79eb3ef108 Add complete Uptime Monitoring API implementation
- Created FastAPI application with SQLite database
- Implemented monitor management endpoints (CRUD operations)
- Added uptime checking functionality with response time tracking
- Included statistics endpoints for uptime percentage and metrics
- Set up database models and Alembic migrations
- Added comprehensive API documentation
- Configured CORS and health check endpoints
2025-06-19 20:40:47 +00:00

3.1 KiB

Uptime Monitoring API

A FastAPI-based uptime monitoring service that allows you to monitor website/endpoint availability and performance.

Features

  • Monitor Management: Create, update, delete, and list website monitors
  • Uptime Checking: Automated and manual uptime checks with response time tracking
  • Statistics: Get uptime percentage, average response times, and check history
  • RESTful API: Full REST API with OpenAPI documentation
  • SQLite Database: Lightweight database for storing monitors and check results

API Endpoints

Base Endpoints

  • GET / - API information and navigation
  • GET /health - Health check endpoint
  • GET /docs - Interactive API documentation (Swagger UI)
  • GET /redoc - Alternative API documentation

Monitor Endpoints

  • POST /api/v1/monitors - Create a new monitor
  • GET /api/v1/monitors - List all monitors
  • GET /api/v1/monitors/{monitor_id} - Get specific monitor
  • PUT /api/v1/monitors/{monitor_id} - Update monitor
  • DELETE /api/v1/monitors/{monitor_id} - Delete monitor
  • GET /api/v1/monitors/{monitor_id}/checks - Get monitor check history
  • GET /api/v1/monitors/{monitor_id}/stats - Get monitor statistics

Check Endpoints

  • POST /api/v1/checks/run/{monitor_id} - Run check for specific monitor
  • POST /api/v1/checks/run-all - Run checks for all active monitors

Installation & Setup

  1. Install dependencies:
pip install -r requirements.txt
  1. Run database migrations (optional - tables are created automatically):
alembic upgrade head
  1. Start the application:
uvicorn main:app --host 0.0.0.0 --port 8000 --reload

The API will be available at http://localhost:8000

Usage Examples

Create a Monitor

curl -X POST "http://localhost:8000/api/v1/monitors" \
     -H "Content-Type: application/json" \
     -d '{
       "name": "My Website",
       "url": "https://example.com",
       "method": "GET",
       "timeout": 30,
       "interval": 300,
       "is_active": true
     }'

Run a Check

curl -X POST "http://localhost:8000/api/v1/checks/run/1"

Get Monitor Statistics

curl "http://localhost:8000/api/v1/monitors/1/stats"

Monitor Configuration

When creating a monitor, you can configure:

  • name: Human-readable name for the monitor
  • url: The URL to monitor
  • method: HTTP method (GET, POST, etc.) - defaults to GET
  • timeout: Request timeout in seconds - defaults to 30
  • interval: Check interval in seconds - defaults to 300 (5 minutes)
  • is_active: Whether the monitor is active - defaults to true

Database

The application uses SQLite database located at /app/storage/db/db.sqlite. The database contains:

  • monitors: Store monitor configurations
  • uptime_checks: Store check results and history

Environment Variables

No environment variables are required for basic operation. The application uses SQLite with default settings.

Development

Linting

ruff check .
ruff format .

Database Migrations

alembic revision --autogenerate -m "Description"
alembic upgrade head