我想找到 10 分钟内以“sendsms”开头的所有 pod 的警报总数。
我可以使用label_replace()在即时向量上执行此操作。但是当我想对超过 10 分钟的数据执行此操作时,它无法工作,因为 label_replace 仅适用于即时向量。
举例说明问题:
ALERTS{alertname="CPUThrottlingHigh",pod="sendsms-dbed"} 10
ALERTS{alertname="CPUThrottlingHigh",pod="sendsms-ebed"} 20
ALERTS{alertname="CPUThrottlingHigh",pod="sendsms-fbed"} 30
Run Code Online (Sandbox Code Playgroud)
ALERTS{alertname="CPUThrottlingHigh",pod="sendmail-gbed"} 60
ALERTS{alertname="CPUThrottlingHigh",pod="sendmail-hbed"} 70
ALERTS{alertname="CPUThrottlingHigh",pod="sendmail-ibed"} 80
Run Code Online (Sandbox Code Playgroud)
使用标签替换我可以使用正则表达式添加一个新标签,然后我可以将其分组并获得结果。
label_replace(ALERTS{alertname="CPUThrottlingHigh", "podname", "$1", "pod", "([a-z-A-Z]+)-.*")
ALERTS{alertname="CPUThrottlingHigh",pod="sendsms-dbed", podname="sendsms"} 10
ALERTS{alertname="CPUThrottlingHigh",pod="sendsms-dbed", podname="sendsms"} 10
Run Code Online (Sandbox Code Playgroud)
如何在 10 分钟内为 ALERTS 执行此操作并计算总和?
我想要在过去 10 分钟内得到这样的结果
ALERTS{alertname="CPUThrottlingHigh",podname="sendsms"} 60
ALERTS{alertname="CPUThrottlingHigh",podname="sendmail"} 210
Run Code Online (Sandbox Code Playgroud)
目标:找到过去 1 周内创建最多警报的 Pod。