负载均衡重构: 子网感知选择 + 节点健康监控 + 节点注册上报API
- 新增 subnet-aware 负载策略: 根据客户端IP匹配最近/16子网节点 - 节点注册端点 (POST /api/nodes/register): 边缘节点自动注册 - 节点心跳端点 (POST /api/nodes/heartbeat): 上报CPU/RAM/带宽/连接数 - 健康汇总 (GET /api/nodes/health): 服务端汇总所有节点状态 - 配置节点新增subnet/is_origin字段 - 前端NodeManager: 实时健康状态/CPU/RAM进度条/带宽/连接数 - X-Forwarded-For/X-Real-IP透传支持客户端IP
This commit is contained in:
1 parent
5f19fc6aa5
commit
980b91f41f
7 files changed
+319
-87
No files matched your search
@@ -69,12 +69,6 @@ class StreamService:
|
||||
status=StreamStatus.live,
|
||||
started_at=datetime.utcnow(),
|
||||
)
|
||||
assigned = [n["id"] for n in lb.get_enabled_nodes()]
|
||||
await self.update_stream(
|
||||
stream.id,
|
||||
assigned_nodes=json.dumps(assigned),
|
||||
multicast_enabled=multicast_detector.is_available(),
|
||||
)
|
||||
rtmp_url = media_service.get_rtmp_url(stream_key)
|
||||
transcode_mgr.start_transcode(stream_key, rtmp_url)
|
||||
|
||||
@@ -89,20 +83,22 @@ class StreamService:
|
||||
)
|
||||
transcode_mgr.stop_transcode(stream_key)
|
||||
|
||||
async def get_watch_urls(self, stream_key: str):
|
||||
nodes = lb.get_enabled_nodes()
|
||||
async def get_watch_urls(self, stream_key: str, client_ip: str | None = None):
|
||||
best_node = lb.select_best_node(client_ip)
|
||||
if not best_node:
|
||||
best_node = lb.get_enabled_nodes()[0] if lb.get_enabled_nodes() else None
|
||||
|
||||
lines = []
|
||||
for node in nodes:
|
||||
if best_node:
|
||||
base_hls = f"/hls/{stream_key}"
|
||||
line_info = {
|
||||
"node_id": node["id"],
|
||||
"node_name": node["name"],
|
||||
"weight": node["weight"],
|
||||
"node_id": best_node["id"],
|
||||
"node_name": best_node["name"],
|
||||
"weight": best_node["weight"],
|
||||
"type": "hls",
|
||||
"url": f"{base_hls}/index.m3u8",
|
||||
"qualities": [],
|
||||
}
|
||||
base_hls = f"/hls/{stream_key}"
|
||||
line_info["type"] = "hls"
|
||||
line_info["url"] = f"{base_hls}/index.m3u8"
|
||||
|
||||
for quality in settings.qualities:
|
||||
label = quality["label"]
|
||||
line_info["qualities"].append({
|
||||
|
||||
Reference in new issue
Block a user