初级
查询服务实例注册状态
未完成
初级参考
完整示例代码供参考,建议自己理解后重新输入
def solve():
from pyodide.http import open_url
from io import StringIO
import pandas as pd
reg_csv = open_url("https://data.zuihe.com/dbd/ms-iot/state_04/service_registry.csv").read()
reg = pd.read_csv(StringIO(reg_csv))
print("Service Registry:")
for _, row in reg.iterrows():
print(" " + row['service_name'] + " [" + row['instance_id'] + "] " + row['host'] + " v" + row['version'] + " weight=" + str(row['weight']) + " status=" + row['status'] + " conns=" + str(row['connections']))
healthy = reg[reg['status']=='healthy']
print("Healthy: " + str(len(healthy)) + "/" + str(len(reg)))
for svc, grp in reg.groupby('service_name'):
h = len(grp[grp['status']=='healthy'])
print(" " + svc + ": " + str(h) + "/" + str(len(grp)) + " healthy")
示例
输入
solve()
期望输出
Service Registry: data-ingestion [di-1] 10.0.1.11:8080 vv1 weight=100 status=healthy conns=12 data-ingestion [di-2] 10.0.1.12:8080 vv1 weight=100 status=healthy conns=8 data-ingestion [di-3] 10.0.1.13:8080 vv2 weight=20 status=healthy conns=2 alert-engine [ae-1] 10.0.2.11:8090 vv1 weight=100 status=healthy conns=5 alert-engine [ae-2] 10.0.2.12:8090 vv1 weight=100 status=unhealthy conns=0 cmd-dispatcher [cd-1] 10.0.3.11:8091 vv1 weight=100 status=healthy conns=3 Healthy: 5/6 alert-engine: 1/2 healthy cmd-dispatcher: 1/1 healthy data-ingestion: 3/3 healthy
👑
升级 VIP
解锁全部题目,畅通无阻地学习
- ✓ 解锁全部训练包所有题目
- ✓ 查看完整参考代码和提示
- ✓ 浏览器内直接运行 Python 代码
- ✓ 自动批改 + 进度追踪
30天
¥18
1年
¥99
2年
¥158
3年
¥199