← 返回题库
中级

实现服务实例健康检查

未完成
中级参考 代码结构已给出,请填写 ____ 处
def solve():
    from pyodide.http import open_url
    from io import StringIO
    import pandas as pd
    reg_csv = open_url(____).read()
    traffic_csv = open_url(____).read()
    reg = pd.read_csv(StringIO(____))
    traffic = pd.read_csv(StringIO(____))
    def health_score(____):
        inst_traffic = traffic[traffic['____']==instance_id]
        if inst_traffic.empty: return ____
        success_rate = (____).mean()
        avg_latency = inst_traffic['____'].mean()
        score = success_rate * ____ - avg_latency * ____
        return round(____)
    print(____)
    for _, row in reg.iterrows():
        score = health_score(____)
        status = row['____']
        print(____)

示例

输入
solve()
期望输出
实例健康评分:
  di-1 (healthy): score=94.7
  di-2 (healthy): score=94.3
  di-3 (healthy): score=94.9
  ae-1 (healthy): score=0.0
  ae-2 (unhealthy): score=0.0
  cd-1 (healthy): score=0.0
Python 代码 🔒 登录后使用
🔒

登录后即可练习

注册免费账号,在浏览器中直接运行 Python 代码