bsi*_*ngr 10 continuous-integration alert integration-testing automated-tests prometheus
我们即将设置Prometheus用于监控和警报我们的云服务,包括Prometheus服务的连续集成和部署管道以及警报规则/阈值等配置.为此,我正在考虑3个类别,我想编写自动化测试:
我现在最重要的部分是测试警报规则(类别1),但我没有找到工具来做到这一点.我可以想象在部署期间设置一个Prometheus实例,为它提供一些公制样本(担心我将如何使用普罗米修斯的Pull架构?)然后针对它运行查询.
到目前为止我唯一发现的是一篇关于监控普罗米修斯Alertmanager连锁店整个与第三类相关的博客文章.
有没有人做过这样的事情,还是有什么我错过的?
新版本的 Prometheus (2.5) 允许编写警报测试,这里是一个链接。您可以检查点 1 和 2。您必须定义数据和预期输出(例如在 中test.yml):
rule_files:
- alerts.yml
evaluation_interval: 1m
tests:
# Test 1.
- interval: 1m
# Series data.
input_series:
- series: 'up{job="prometheus", instance="localhost:9090"}'
values: '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'
- series: 'up{job="node_exporter", instance="localhost:9100"}'
values: '1+0x6 0 0 0 0 0 0 0 0' # 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0
# Unit test for alerting rules.
alert_rule_test:
# Unit test 1.
- eval_time: 10m
alertname: InstanceDown
exp_alerts:
# Alert 1.
- exp_labels:
severity: page
instance: localhost:9090
job: prometheus
exp_annotations:
summary: "Instance localhost:9090 down"
description: "localhost:9090 of job prometheus has been down for more than 5 minutes."
Run Code Online (Sandbox Code Playgroud)
您可以使用 docker 运行测试:
docker run \
-v $PROJECT/testing:/tmp \
--entrypoint "/bin/promtool" prom/prometheus:v2.5.0 \
test rules /tmp/test.yml
Run Code Online (Sandbox Code Playgroud)
promtool将验证您的InstanceDown文件警报alerts.yml是否处于活动状态。这种方法的优点是您不必启动 Prometheus。