
- 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
57 lines
1.2 KiB
Python
57 lines
1.2 KiB
Python
from datetime import datetime
|
|
from typing import Optional
|
|
from pydantic import BaseModel, HttpUrl
|
|
|
|
|
|
class MonitorBase(BaseModel):
|
|
name: str
|
|
url: HttpUrl
|
|
method: str = "GET"
|
|
timeout: int = 30
|
|
interval: int = 300
|
|
is_active: bool = True
|
|
|
|
|
|
class MonitorCreate(MonitorBase):
|
|
pass
|
|
|
|
|
|
class MonitorUpdate(BaseModel):
|
|
name: Optional[str] = None
|
|
url: Optional[HttpUrl] = None
|
|
method: Optional[str] = None
|
|
timeout: Optional[int] = None
|
|
interval: Optional[int] = None
|
|
is_active: Optional[bool] = None
|
|
|
|
|
|
class MonitorResponse(MonitorBase):
|
|
id: int
|
|
created_at: datetime
|
|
updated_at: Optional[datetime] = None
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
class UptimeCheckResponse(BaseModel):
|
|
id: int
|
|
monitor_id: int
|
|
status_code: Optional[int]
|
|
response_time: Optional[float]
|
|
is_up: bool
|
|
error_message: Optional[str]
|
|
checked_at: datetime
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
class MonitorStats(BaseModel):
|
|
monitor_id: int
|
|
uptime_percentage: float
|
|
total_checks: int
|
|
successful_checks: int
|
|
average_response_time: Optional[float]
|
|
last_check: Optional[datetime]
|