xiaoyukkkk commited on
Commit
57bc038
·
verified ·
1 Parent(s): 23d392c

Delete uptime_tracker.py

Browse files
Files changed (1) hide show
  1. uptime_tracker.py +0 -78
uptime_tracker.py DELETED
@@ -1,78 +0,0 @@
1
- """
2
- Uptime 实时监控追踪器
3
- 类似 Uptime Kuma 的心跳监控,显示最近请求状态
4
- """
5
-
6
- from collections import deque
7
- from datetime import datetime, timezone, timedelta
8
- from typing import Dict, List
9
-
10
- # 北京时区 UTC+8
11
- BEIJING_TZ = timezone(timedelta(hours=8))
12
-
13
- # 每个服务保留最近 60 条心跳记录
14
- MAX_HEARTBEATS = 60
15
-
16
- # 服务配置
17
- SERVICES = {
18
- "api_service": {"name": "API 服务", "heartbeats": deque(maxlen=MAX_HEARTBEATS)},
19
- "account_pool": {"name": "服务资源", "heartbeats": deque(maxlen=MAX_HEARTBEATS)},
20
- "gemini-2.5-flash": {"name": "Gemini 2.5 Flash", "heartbeats": deque(maxlen=MAX_HEARTBEATS)},
21
- "gemini-2.5-pro": {"name": "Gemini 2.5 Pro", "heartbeats": deque(maxlen=MAX_HEARTBEATS)},
22
- "gemini-3-flash-preview": {"name": "Gemini 3 Flash Preview", "heartbeats": deque(maxlen=MAX_HEARTBEATS)},
23
- "gemini-3-pro-preview": {"name": "Gemini 3 Pro Preview", "heartbeats": deque(maxlen=MAX_HEARTBEATS)},
24
- }
25
-
26
- SUPPORTED_MODELS = ["gemini-2.5-flash", "gemini-2.5-pro", "gemini-3-flash-preview", "gemini-3-pro-preview"]
27
-
28
-
29
- def record_request(service: str, success: bool):
30
- """记录请求心跳"""
31
- if service not in SERVICES:
32
- return
33
-
34
- SERVICES[service]["heartbeats"].append({
35
- "time": datetime.now(BEIJING_TZ).strftime("%H:%M:%S"),
36
- "success": success
37
- })
38
-
39
-
40
- def get_realtime_status() -> Dict:
41
- """获取实时状态数据"""
42
- result = {"services": {}}
43
-
44
- for service_id, service_data in SERVICES.items():
45
- heartbeats = list(service_data["heartbeats"])
46
- total = len(heartbeats)
47
- success = sum(1 for h in heartbeats if h["success"])
48
-
49
- # 计算可用率
50
- uptime = (success / total * 100) if total > 0 else 100.0
51
-
52
- # 最近状态
53
- last_status = "unknown"
54
- if heartbeats:
55
- last_status = "up" if heartbeats[-1]["success"] else "down"
56
-
57
- result["services"][service_id] = {
58
- "name": service_data["name"],
59
- "status": last_status,
60
- "uptime": round(uptime, 1),
61
- "total": total,
62
- "success": success,
63
- "heartbeats": heartbeats[-MAX_HEARTBEATS:] # 最近的心跳
64
- }
65
-
66
- result["updated_at"] = datetime.now(BEIJING_TZ).strftime("%Y-%m-%d %H:%M:%S")
67
- return result
68
-
69
-
70
- # 兼容旧接口
71
- async def get_uptime_summary(days: int = 90) -> Dict:
72
- """兼容旧接口,返回实时数据"""
73
- return get_realtime_status()
74
-
75
-
76
- async def uptime_aggregation_task():
77
- """后台任务(保留兼容性,实际不需要聚合)"""
78
- pass