Fix service status

This commit is contained in:
2025-12-20 02:28:41 +07:00
parent c645171671
commit 243abe55b5
5 changed files with 210 additions and 33 deletions

View File

@@ -90,7 +90,7 @@ def get_latency_history(service_name: str, hours: int = 24) -> list[dict]:
conn = get_connection()
cursor = conn.cursor()
since = datetime.now() - timedelta(hours=hours)
since = datetime.utcnow() - timedelta(hours=hours)
cursor.execute("""
SELECT latency_ms, status, checked_at
FROM metrics
@@ -116,7 +116,7 @@ def get_uptime_stats(service_name: str, hours: int = 24) -> dict:
conn = get_connection()
cursor = conn.cursor()
since = datetime.now() - timedelta(hours=hours)
since = datetime.utcnow() - timedelta(hours=hours)
cursor.execute("""
SELECT COUNT(*) as total,
@@ -143,7 +143,7 @@ def get_avg_latency(service_name: str, hours: int = 24) -> Optional[float]:
conn = get_connection()
cursor = conn.cursor()
since = datetime.now() - timedelta(hours=hours)
since = datetime.utcnow() - timedelta(hours=hours)
cursor.execute("""
SELECT AVG(latency_ms) as avg_latency
FROM metrics
@@ -249,11 +249,11 @@ def get_ssl_info(domain: str) -> Optional[dict]:
return None
def cleanup_old_metrics(days: int = 1):
"""Delete metrics older than specified days (default: 24 hours)."""
def cleanup_old_metrics(hours: int = 24):
"""Delete metrics older than specified hours (default: 24 hours)."""
conn = get_connection()
cursor = conn.cursor()
cutoff = datetime.now() - timedelta(days=days)
cutoff = datetime.utcnow() - timedelta(hours=hours)
cursor.execute("DELETE FROM metrics WHERE checked_at < ?", (cutoff.isoformat(),))
deleted = cursor.rowcount
conn.commit()