
- 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
30 lines
1.1 KiB
Python
30 lines
1.1 KiB
Python
from sqlalchemy import Column, Integer, String, DateTime, Boolean, Float, Text
|
|
from sqlalchemy.sql import func
|
|
from app.db.base import Base
|
|
|
|
|
|
class Monitor(Base):
|
|
__tablename__ = "monitors"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
name = Column(String, nullable=False, index=True)
|
|
url = Column(String, nullable=False)
|
|
method = Column(String, default="GET")
|
|
timeout = Column(Integer, default=30)
|
|
interval = Column(Integer, default=300) # Check interval in seconds
|
|
is_active = Column(Boolean, default=True)
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
|
|
|
|
|
class UptimeCheck(Base):
|
|
__tablename__ = "uptime_checks"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
monitor_id = Column(Integer, nullable=False, index=True)
|
|
status_code = Column(Integer)
|
|
response_time = Column(Float) # Response time in milliseconds
|
|
is_up = Column(Boolean, nullable=False)
|
|
error_message = Column(Text, nullable=True)
|
|
checked_at = Column(DateTime(timezone=True), server_default=func.now())
|