完善直播节点监控与边缘代理
This commit is contained in:
1 parent
058bb4b99f
commit
20cd99efa4
19 files changed
+401
-47
No files matched your search
@@ -132,6 +132,12 @@ class LoadBalancer:
|
||||
"bandwidth_mbps": h.get("bandwidth_mbps"),
|
||||
"active_connections": h.get("active_connections"),
|
||||
"hls_readers": h.get("hls_readers"),
|
||||
"network_in_mbps": h.get("network_in_mbps"),
|
||||
"network_out_mbps": h.get("network_out_mbps"),
|
||||
"viewer_count": h.get("viewer_count"),
|
||||
"frame_drop_indicators": h.get("frame_drop_indicators"),
|
||||
"packet_loss_indicators": h.get("packet_loss_indicators"),
|
||||
"media_metrics_available": h.get("media_metrics_available", False),
|
||||
} if h else None,
|
||||
}
|
||||
return result
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from config import settings
|
||||
|
||||
|
||||
STORE_PATH = Path(__file__).resolve().parent.parent / "nodes.json"
|
||||
|
||||
|
||||
def load_nodes() -> None:
|
||||
if not STORE_PATH.exists():
|
||||
return
|
||||
try:
|
||||
nodes = json.loads(STORE_PATH.read_text(encoding="utf-8"))
|
||||
except (OSError, json.JSONDecodeError):
|
||||
return
|
||||
if isinstance(nodes, list):
|
||||
settings.edge_nodes = nodes
|
||||
|
||||
|
||||
def save_nodes() -> None:
|
||||
temporary = STORE_PATH.with_suffix(".json.tmp")
|
||||
temporary.write_text(
|
||||
json.dumps(settings.edge_nodes, ensure_ascii=False, indent=2),
|
||||
encoding="utf-8",
|
||||
)
|
||||
temporary.replace(STORE_PATH)
|
||||
@@ -7,6 +7,7 @@ from services.multicast_detector import multicast_detector
|
||||
from services.transcoder import transcode_mgr
|
||||
from config import settings
|
||||
import json
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
class StreamService:
|
||||
@@ -17,13 +18,19 @@ class StreamService:
|
||||
cover_url: str | None = None,
|
||||
scheduled_at: str | None = None) -> Stream:
|
||||
import uuid
|
||||
scheduled_datetime = None
|
||||
if scheduled_at:
|
||||
try:
|
||||
scheduled_datetime = datetime.fromisoformat(scheduled_at.replace("Z", "+00:00"))
|
||||
except ValueError as exc:
|
||||
raise ValueError("预定开播时间格式无效") from exc
|
||||
stream = Stream(
|
||||
title=title,
|
||||
description=description,
|
||||
cover_url=cover_url,
|
||||
stream_key=uuid.uuid4().hex,
|
||||
status=StreamStatus.pending,
|
||||
scheduled_at=scheduled_at,
|
||||
scheduled_at=scheduled_datetime,
|
||||
)
|
||||
self.db.add(stream)
|
||||
await self.db.commit()
|
||||
@@ -113,4 +120,8 @@ class StreamService:
|
||||
"lines": lines,
|
||||
"qualities": [{"label": q["label"], "width": q["width"], "height": q["height"]} for q in settings.qualities],
|
||||
"multicast_available": multicast_detector.is_available(),
|
||||
"selected_node": {
|
||||
"id": best_node["id"],
|
||||
"name": best_node["name"],
|
||||
} if best_node else None,
|
||||
}
|
||||
Reference in new issue
Block a user