
- 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
3.1 KiB
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 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
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"
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