import time import requests from huggingface_hub import HfApi REPO_ID = "cefrefdwe/warp-proxy-test-1769367429" SPACE_URL = f"https://{REPO_ID.replace('/', '-').replace('_', '-')}.hf.space" def check_status(): api = HfApi() print(f"🔍 正在监控 Space: {REPO_ID}") print(f"🌐 目标 URL: {SPACE_URL}") while True: try: # 1. 检查 Space 运行时状态 repo_info = api.repo_info(repo_id=REPO_ID, repo_type="space") runtime = repo_info.runtime stage = runtime.stage print(f"[{time.strftime('%H:%M:%S')}] 🏗 部署状态: {stage.upper()}") if stage == "RUNNING": # 2. 检查 HTTP 响应 try: resp = requests.get(SPACE_URL, timeout=10) if resp.status_code == 200: print(f"[{time.strftime('%H:%M:%S')}] ✅ 服务正常! HTTP 200 OK") # 尝试解析内容看是否有 Stats if "System Metrics" in resp.text: print(" 📊 监测到统计数据面板,应用正在运行逻辑") else: print(" ℹ️ 面板可访问 (暂无统计数据)") return True else: print(f"[{time.strftime('%H:%M:%S')}] ⚠️ 服务响应异常: HTTP {resp.status_code}") except requests.RequestException as e: print(f"[{time.strftime('%H:%M:%S')}] ❌ 无法连接服务: {e}") elif stage == "BUILDING": print(" ⏳ 正在构建镜像中,请耐心等待...") elif stage == "APP_STARTING": print(" 🚀 应用启动中...") elif stage in ["BUILD_ERROR", "RUNTIME_ERROR"]: print(f"[{time.strftime('%H:%M:%S')}] ❌ 部署失败! 状态: {stage}") return False time.sleep(10) except Exception as e: print(f"❌ 监控脚本出错: {e}") time.sleep(10) if __name__ == "__main__": check_status()