最近三个都超了吗

👁️ 2 人浏览 💬 0 人评论 ❤️ 添加收藏

按模型,sustained([2,5,6,7], 4, 3) 交回什么?

贯穿本节的运维模型(判题机纯 Python、无网,这是它的确定模型,见 spine.py):服务上线后靠日志/指标/健康/告警盯住它。

告警阈值:over(值,阈值)count_over 超阈值几个、sustained(采样,阈值,n)=最近 n 个都超(持续才报、避免抖动)、should_clear=最新回落可消警。

def over(value, threshold):
    """这个值有没有超过阈值。"""
    return value > threshold


def count_over(samples, threshold):
    """一串采样里有几个超过阈值。"""
    return sum(1 for s in samples if s > threshold)


def sustained(samples, threshold, n):
    """最近 n 个采样是不是全超阈值(持续超过才告警,避免抖动)。"""
    return len(samples) >= n and all(s > threshold for s in samples[-n:])


def should_clear(samples, threshold):
    """最新采样已回落到阈值内,可以消警了吗。"""
    return samples[-1] <= threshold

print(sustained([2, 5, 6, 7], 4, 3))
提交你的答案
请登录后提交答案。
去登录
代码编辑器
Ctrl + Enter 运行
本次输入:
输出:

                        
👩‍🏫
AI
💬 题目评论

全部评论