Fix status--service
This commit is contained in:
@@ -91,12 +91,13 @@ def get_latency_history(service_name: str, hours: int = 24) -> list[dict]:
|
||||
cursor = conn.cursor()
|
||||
|
||||
since = datetime.utcnow() - timedelta(hours=hours)
|
||||
# Use strftime format to match SQLite CURRENT_TIMESTAMP format (no 'T')
|
||||
cursor.execute("""
|
||||
SELECT latency_ms, status, checked_at
|
||||
FROM metrics
|
||||
WHERE service_name = ? AND checked_at > ? AND latency_ms IS NOT NULL
|
||||
ORDER BY checked_at ASC
|
||||
""", (service_name, since.isoformat()))
|
||||
""", (service_name, since.strftime("%Y-%m-%d %H:%M:%S")))
|
||||
|
||||
rows = cursor.fetchall()
|
||||
conn.close()
|
||||
@@ -123,7 +124,7 @@ def get_uptime_stats(service_name: str, hours: int = 24) -> dict:
|
||||
SUM(CASE WHEN status = 'operational' THEN 1 ELSE 0 END) as successful
|
||||
FROM metrics
|
||||
WHERE service_name = ? AND checked_at > ?
|
||||
""", (service_name, since.isoformat()))
|
||||
""", (service_name, since.strftime("%Y-%m-%d %H:%M:%S")))
|
||||
|
||||
row = cursor.fetchone()
|
||||
conn.close()
|
||||
@@ -148,7 +149,7 @@ def get_avg_latency(service_name: str, hours: int = 24) -> Optional[float]:
|
||||
SELECT AVG(latency_ms) as avg_latency
|
||||
FROM metrics
|
||||
WHERE service_name = ? AND checked_at > ? AND latency_ms IS NOT NULL
|
||||
""", (service_name, since.isoformat()))
|
||||
""", (service_name, since.strftime("%Y-%m-%d %H:%M:%S")))
|
||||
|
||||
row = cursor.fetchone()
|
||||
conn.close()
|
||||
@@ -231,7 +232,7 @@ def save_ssl_info(domain: str, issuer: str, expires_at: datetime, days_until_exp
|
||||
INSERT OR REPLACE INTO ssl_certificates
|
||||
(domain, issuer, expires_at, days_until_expiry, checked_at)
|
||||
VALUES (?, ?, ?, ?, CURRENT_TIMESTAMP)
|
||||
""", (domain, issuer, expires_at.isoformat(), days_until_expiry))
|
||||
""", (domain, issuer, expires_at.strftime("%Y-%m-%d %H:%M:%S"), days_until_expiry))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
@@ -254,7 +255,7 @@ def cleanup_old_metrics(hours: int = 24):
|
||||
conn = get_connection()
|
||||
cursor = conn.cursor()
|
||||
cutoff = datetime.utcnow() - timedelta(hours=hours)
|
||||
cursor.execute("DELETE FROM metrics WHERE checked_at < ?", (cutoff.isoformat(),))
|
||||
cursor.execute("DELETE FROM metrics WHERE checked_at < ?", (cutoff.strftime("%Y-%m-%d %H:%M:%S"),))
|
||||
deleted = cursor.rowcount
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
Reference in New Issue
Block a user