【发布时间】:2020-04-15 17:41:59
【问题描述】:
我正在使用 Telegraf 和 Prometheus 来监控我的本地服务,例如 OpenHab 和我的 Grafana 实例。
http_response 插件可能会产生以下结果:
http_response_http_response_code{host="master-pi",instance="192.168.2.15:9126",job="telegraf-master-pi",method="GET",result="success",result_type="success",server="http://www.grafana.local",status_code="200"} 200
http_response_http_response_code{host="master-pi",instance="192.168.2.15:9126",job="telegraf-master-pi",method="GET",result="success",result_type="success",server="http://www.grafana.local",status_code="502"} 502
http_response_http_response_code{host="master-pi",instance="192.168.2.15:9126",job="telegraf-master-pi",method="GET",result="success",result_type="success",server="http://www.thuis.local/start/index",status_code="200"} 200
现在我想要一个警报,只要过去 30 分钟的 !200 status_code 计数高于 200 status_code 计数,它就会通知我。
我从简单开始:
alert: service_down_external
expr: http_response_http_response_code{status_code!~"200|302"}
for: 35m
labels:
severity: high
这很好用,但问题是这不适用于我不是每 10 秒而是每 5 到 30 分钟监控一次的服务(因为我想减少某些 API 的负载)。
所以我想,让我们尝试另一种方式:
expr: count_over_time(http_response_http_response_code{status_code!~"200|302"}[30m]) > on(job, instance, method, server) count_over_time(http_response_http_response_code{status_code=~"200|302"}[30m])
这似乎很有希望,但不幸的是,如果根本没有 200/302 响应,则将无法正常工作,在这种情况下会返回“无数据”。
不过,我还是把它除以总金额:
count_over_time(http_response_http_response_code{status_code!~"200|302"}[300m]) > on(job, instance, method, server) count_over_time(http_response_http_response_code[300m])
但是,结果是:
Error executing query: found duplicate series for the match group {instance="192.168.2.15:9126", job="telegraf-master-pi", method="GET", server="http://www.grafana.local/series"} on the right hand-side of the operation: [{host="master-pi", instance="192.168.2.15:9126", job="telegraf-master-pi", method="GET", result="success", result_type="success", server="http://www.grafana.local/series", status_code="502"}, {host="master-pi", instance="192.168.2.15:9126", job="telegraf-master-pi", method="GET", result="success", result_type="success", server="http://www.grafana.local/series", status_code="200"}];many-to-many matching not allowed: matching labels must be unique on one side
在尝试忽略时:
count_over_time(http_response_http_response_code{status_code!~"200|302"}[30m]) >ignoring(status_code) count_over_time(http_response_http_response_code[30m])
发生同样的错误。
当 http 响应在过去 30 分钟内仅返回 5xx 错误时,是否有其他方法可以提醒我?
【问题讨论】:
标签: prometheus telegraf prometheus-alertmanager telegraf-inputs-plugin