
- Added custom CORS middleware to ensure headers are always present - Added explicit OPTIONS handler for preflight requests - Used both custom and standard CORS middleware for maximum compatibility - This should definitively resolve CORS blocking issues
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 navigationGET /health
- Health check endpointGET /docs
- Interactive API documentation (Swagger UI)GET /redoc
- Alternative API documentation
Monitor Endpoints
POST /api/v1/monitors
- Create a new monitorGET /api/v1/monitors
- List all monitorsGET /api/v1/monitors/{monitor_id}
- Get specific monitorPUT /api/v1/monitors/{monitor_id}
- Update monitorDELETE /api/v1/monitors/{monitor_id}
- Delete monitorGET /api/v1/monitors/{monitor_id}/checks
- Get monitor check historyGET /api/v1/monitors/{monitor_id}/stats
- Get monitor statistics
Check Endpoints
POST /api/v1/checks/run/{monitor_id}
- Run check for specific monitorPOST /api/v1/checks/run-all
- Run checks for all active monitors
Scheduler Endpoints
GET /api/v1/scheduler/status
- Get scheduler status and running jobsPOST /api/v1/scheduler/start
- Start the background schedulerPOST /api/v1/scheduler/stop
- Stop the background schedulerPOST /api/v1/scheduler/restart
- Restart scheduler and reschedule all monitors
Installation & Setup
- Install dependencies:
pip install -r requirements.txt
- Run database migrations (optional - tables are created automatically):
alembic upgrade head
- 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
Languages
Python
97.9%
Mako
2.1%