如何以简化的方式编写prometheus复杂警报规则



我的警报规则的表达式如下所示,我需要用相同的表达式编写多达20个警报规则,但方法名称和服务名称因规则而异,这使得我的alert.yaml文件很难看。任何人都可以指定简化的方式来编写这些类型的警报吗

表达式:

( sum(rate(grpc_server_handling_seconds_bucket{endpoint="http",grpc_method="MethodName",grpc_service="ServiceName",grpc_type="unary",job="JobName",le="1",service="ServiceName"}[15m])) by (job)+sum(rate(grpc_server_handling_seconds_bucket{endpoint="http",grpc_method="MethodName",grpc_service="ServiceName",grpc_type="unary",job="JobName",le="5",service="ServiceName"}[15m])) by (job) ) / 2 /  sum(rate(grpc_server_handling_seconds_count{endpoint="http",grpc_method="MethodName",grpc_service="ServiceName",grpc_type="unary",job="JobNAme",service="ServiceName"}[15m])) by (job) < 0.9

如果您想提醒所有方法名称&service_names您可以跳过在标签选择器中添加这些,完全是

(
(
sum by (job) (rate(grpc_server_handling_seconds_bucket{endpoint="http",grpc_type="unary",job="JobName",le="1",service="ServiceName"}[15m])) 
+
sum by (job) (rate(grpc_server_handling_seconds_bucket{endpoint="http",grpc_type="unary",job="JobName",le="5",service="ServiceName"}[15m]))
) / 2 
/  
sum by (job)(rate(grpc_server_handling_seconds_count{endpoint="http",grpc_type="unary",job="JobNAme",service="ServiceName"}[15m]))
) < 0.9

否则,您可以使用一些模板工具(如ytt(为method_names&服务名称

最新更新