2.9.2. 创建提取示例警报
您可以创建在以下情况下通知您的警报:
-
在指定的
for持续时间内无法提取对象或对象不可用 -
在指定的
for持续时间内达到或超过提取示例阈值
先决条件
-
您可以使用具有
cluster-admin角色的用户访问集群,也可以使用在openshift-user-workload-monitoring项目中具有user-workload-monitoring-config-edit角色的用户访问集群。 - 您已为用户定义的项目启用了监控。
-
您已创建了
user-workload-monitoring-configConfigMap对象。 -
您已经使用
enforcedSampleLimit限制了用户定义的项目中每个目标提取可接受的示例数量。 -
已安装 OpenShift CLI(
oc)。
流程
创建一个包含警报的 YAML 文件,用于在目标停机以及即将达到强制的示例限制时通知您。本例中的文件名为
monitoring-stack-alerts.yaml:apiVersion: monitoring.coreos.com/v1 kind: PrometheusRule metadata: labels: prometheus: k8s role: alert-rules name: monitoring-stack-alerts1 namespace: ns12 spec: groups: - name: general.rules rules: - alert: TargetDown3 annotations: message: '{{ printf "%.4g" $value }}% of the {{ $labels.job }}/{{ $labels.service }} targets in {{ $labels.namespace }} namespace are down.'4 expr: 100 * (count(up == 0) BY (job, namespace, service) / count(up) BY (job, namespace, service)) > 10 for: 10m5 labels: severity: warning6 - alert: ApproachingEnforcedSamplesLimit7 annotations: message: '{{ $labels.container }} container of the {{ $labels.pod }} pod in the {{ $labels.namespace }} namespace consumes {{ $value | humanizePercentage }} of the samples limit budget.'8 expr: scrape_samples_scraped/50000 > 0.89 for: 10m10 labels: severity: warning11 - 1
- 定义警报规则的名称。
- 2
- 指定要部署警报规则的用户定义的项目。
- 3
- 如果在
for持续时间内无法提取目标或者目标不可用,则TargetDown警报将触发。 - 4
TargetDown警报触发时输出的消息。- 5
- 在这个持续时间内必须满足
TargetDown警报的条件才会触发该警报。 - 6
- 定义
TargetDown警报的严重性。 - 7
- 当在指定的
for持续时间内达到或超过定义的提取示例阈值时,ApproachingEnforcedSamplesLimit警报将触发。 - 8
- 当
ApproachingEnforcedSamplesLimit警报触发时输出的消息。 - 9
ApproachingEnforcedSamplesLimit警报的阈值。在本例中,当每个目标提取的示例数量超过强制示例限制50000的 80% 时,警报将触发。在警报触发前,还必须已经过了for持续时间。表达式scrape_samples_scraped/<number> > <threshold>中的<number>必须与user-workload-monitoring-configConfigMap对象中定义的enforcedSampleLimit值匹配。- 10
- 在这个持续时间内必须满足
ApproachingEnforcedSamplesLimit警报的条件才会触发该警报。 - 11
- 定义
ApproachingEnforcedSamplesLimit警报的严重性。
将配置应用到用户定义的项目中:
$ oc apply -f monitoring-stack-alerts.yaml