Я использую 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
Теперь я хочу предупреждение, которое уведомляет меня всякий раз, когда счет! 200 status_code за последние 30 минут превышает число 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 возвращает только 5xx ошибок за последние 30 минут?