gpt4 book ai didi

prometheus - 如何在容器重新启动时发出警报?

转载 作者:行者123 更新时间:2023-12-04 00:59:55 26 4
gpt4 key购买 nike

我喜欢使用 Prometheus 和 cAdvisor 监视容器,以便在容器重新启动时收到警报。我想知道是否有人为此提供了 Prometheus 警报示例。

最佳答案

我使用以下 Prometheus 警报规则来查找一小时内容器重新启动(可以修改为最大时间),它可能对您有所帮助。

Prometheus 警报规则示例

ALERT ContainerRestart/PodRestart
IF rate(kube_pod_container_status_restarts[1h]) * 3600 > 1
FOR 5s
LABELS {action_required = "true", severity="critical/warning/info"}
ANNOTATIONS {DESCRIPTION="Pod {{$labels.namespace}}/{{$labels.pod}} restarting more than once during last one hours.",
SUMMARY="Container {{ $labels.container }} in Pod {{$labels.namespace}}/{{$labels.pod}} restarting more than once times during last one hours."}

rate()

rate(v range-vector) calculates the per-second average rate of increase of the time series in the range vector. Breaks in monotonicity (such as counter resets due to target restarts) are automatically adjusted for. Also, the calculation extrapolates to the ends of the time range, allowing for missed scrapes or imperfect alignment of scrape cycles with the range's time period. The following example expression returns the per-second rate of HTTP requests as measured over the last 5 minutes, per time series in the range vector:


rate(http_requests_total{job="api-server"}[5m])

rate should only be used with counters. It is best suited for alerting, and for graphing of slow-moving counters.

Note that when combining rate() with an aggregation operator (e.g. sum()) or a function aggregating over time (any function ending in _over_time), always take a rate() first, then aggregate. Otherwise rate() cannot detect counter resets when your target restarts.


kube_pod_container_status_restarts_total

Metric Type: Counter

Labels/Tags: container=container-name, namespace=pod-namespace,pod=pod-name

Description: The number of container restarts per pod

关于prometheus - 如何在容器重新启动时发出警报?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41452930/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com