MCPcopy Create free account
hub / github.com/THESIS-AGENT/AIRouter / check_healthy

Method check_healthy

LoadBalancing.py:29–56  ·  view source on GitHub ↗

从本地健康检查服务获取API健康状态数据 Returns: dict: 包含时间戳、检查间隔和健康数据的字典

()

Source from the content-addressed store, hash-verified

27class Harness_localAPI:
28 @staticmethod
29 def check_healthy():
30 """从本地健康检查服务获取API健康状态数据
31
32 Returns:
33 dict: 包含时间戳、检查间隔和健康数据的字典
34 """
35 logger = logging.getLogger(__name__)
36 # 防止日志向上传播,避免重复打印
37 logger.propagate = False
38 try:
39 # 调用本地健康检查服务API
40 logger.info("正在调用健康检查服务API获取健康状态数据")
41 response = requests.get(API_HEALTH_CHECK_URL, timeout=INNER_TIMEOUT)
42 if response.status_code == 200:
43 result = response.json()
44 # 将字符串键转换为元组键
45 if "data" in result:
46 result["data"] = {tuple(key.split("|")): [np.nan if v is None else v for v in value] for key, value in result["data"].items()}
47 logger.info("成功获取健康状态数据")
48 return result
49 else:
50 # 如果API调用失败,返回空数据结构和当前时间
51 logger.error(f"健康检查API返回错误状态码: {response.status_code}")
52 return {"timestamp": datetime.now().isoformat(), "check_timer_span": 15, "data": {}}
53 except Exception as e:
54 # 出现异常时记录错误并返回空数据结构
55 logger.error(f"获取健康状态数据时出错: {str(e)}")
56 return {"timestamp": datetime.now().isoformat(), "check_timer_span": 15, "data": {}}
57
58 @staticmethod
59 def get_api_key(source_name):

Callers 3

__init__Method · 0.80
get_configMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected