Prometheus仪表指标的联合
这是我的指标代码:
from prometheus_client import Gauge
probe = Gauge('probe_success', '1 - probe success, 0 - probe failure'
['probe_type', 'target', 'timeout', 'service', 'namespace', 'reason'])
如果对地址的请求成功,则最终值为1,如果发生某些错误,则值为0。
def probe_success(probe_type, target, timeout, service, namespace, reason, value):
probe.labels(probe_type, target, timeout, service, namespace, reason).set(value)
这就是我的指标的样子:
probe_success{namespace="test",probe_type="http",reason="MissingSchema",service="servicename",target="ddress-test1",timeout="5"} 0.0
probe_success{namespace="test",probe_type="http",reason="ConnectionError",service="servicename",target="http://address-test2",timeout="10"} 0.0
probe_success{namespace="test-2",probe_type="http",reason="",service="servicename",target="https://www.google.com",timeout="5"} 1.0
那么我如何测试这些指标。我阅读了有关registry.get_sample_value的信息,但我没有看到如何在量规组方法上使用它。总的来说,我不知道如何构建适当的测试用例。如果有人有建议,我会很高兴阅读它们。
Here is my metrics code:
from prometheus_client import Gauge
probe = Gauge('probe_success', '1 - probe success, 0 - probe failure'
['probe_type', 'target', 'timeout', 'service', 'namespace', 'reason'])
If request to the address is successful the value in the end is 1, if some error occurs the value is 0.
def probe_success(probe_type, target, timeout, service, namespace, reason, value):
probe.labels(probe_type, target, timeout, service, namespace, reason).set(value)
And this is how my metrics look like:
probe_success{namespace="test",probe_type="http",reason="MissingSchema",service="servicename",target="ddress-test1",timeout="5"} 0.0
probe_success{namespace="test",probe_type="http",reason="ConnectionError",service="servicename",target="http://address-test2",timeout="10"} 0.0
probe_success{namespace="test-2",probe_type="http",reason="",service="servicename",target="https://www.google.com",timeout="5"} 1.0
So how could I test these metrics. I read about REGISTRY.get_sample_value but I didn't see how can I use it on gauge set method. In general I don't have idea how to build appropriate test cases. If anyone has suggestions I will be pleased to read them.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我的解决方案:
这是一个有解释的示例,但具有反向指标:
https://www.robustperception.io/www.robustperception.io/测试促进仪式
Here is my solution:
Here is an example with explanation but with Counter metrics:
https://www.robustperception.io/how-to-unit-test-prometheus-instrumentation