Automated Action 2a70291924 Fix CORS configuration for frontend access
- Set allow_credentials=False when using wildcard origins
- Added explicit OPTIONS handler for preflight requests
- Simplified CORS configuration to be more permissive
- This should resolve CORS blocking from frontend applications
2025-06-20 11:49:31 +00:00
2025-06-19 20:34:53 +00:00

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
  • Automatic Scheduling: Background scheduler runs uptime checks at configured intervals
  • 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

Scheduler Endpoints

  • GET /api/v1/scheduler/status - Get scheduler status and running jobs
  • POST /api/v1/scheduler/start - Start the background scheduler
  • POST /api/v1/scheduler/stop - Stop the background scheduler
  • POST /api/v1/scheduler/restart - Restart scheduler and reschedule all 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"

Check Scheduler Status

curl "http://localhost:8000/api/v1/scheduler/status"

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

Automatic Scheduling

The API includes a background scheduler that automatically runs uptime checks for all active monitors:

  • Automatic Start: The scheduler starts automatically when the application launches
  • Individual Intervals: Each monitor runs on its own configured interval (default 5 minutes)
  • Real-time Updates: Creating, updating, or deleting monitors automatically adjusts the scheduler
  • Logging: All check results are logged with timestamps and status information
  • Scheduler Management: Use the scheduler endpoints to check status, start, stop, or restart the scheduler

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
Description
Project: Uptime Monitoring API
Readme 54 KiB
Languages
Python 97.9%
Mako 2.1%