← 返回题库
中级

生成Prometheus格式指标

未完成
中级参考 代码结构已给出,请填写 ____ 处
def solve():
    from pyodide.http import open_url
    from io import StringIO
    import pandas as pd
    metrics_csv = open_url(____).read()
    metrics = pd.read_csv(StringIO(____))
    lines = []
    lines.append(____)
    lines.append(____)
    for _, row in metrics.iterrows():
        dtype = str(____) if str(____) not in (____) else '____'
        lines.append('____' + row['____'] + '____' + dtype + '____' + str(____))
    lines.append(____)
    lines.append(____)
    for _, row in metrics.iterrows():
        dtype = str(____) if str(____) not in (____) else '____'
        lines.append('____' + row['____'] + '____' + dtype + '____' + str(____))
    for line in lines[:____]:
        print(____)
    print(____)

示例

输入
solve()
期望输出
# HELP iot_upload_total Total device uploads
# TYPE iot_upload_total counter
iot_upload_total{service="data-ingestion",device_type="temperature"} 150
iot_upload_total{service="data-ingestion",device_type="vibration"} 80
iot_upload_total{service="data-ingestion",device_type="pressure"} 60
iot_upload_total{service="alert-engine",device_type="all"} 30
# HELP iot_p99_latency_ms P99 latency in ms
# TYPE iot_p99_latency_ms gauge
iot_p99_latency_ms{service="data-ingestion",device_type="temperature"} 250
iot_p99_latency_ms{service="data-ingestion",device_type="vibration"} 280
iot_p99_latency_ms{service="data-ingestion",device_type="pressure"} 850
iot_p99_latency_ms{service="alert-engine",device_type="all"} 400
... (total 12 metric lines)
Python 代码 🔒 登录后使用
🔒

登录后即可练习

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