HTTP 客户端请求指标 prometheus grafana

HTTP client request metrics prometheus grafana

我有兴趣监视我的应用程序使用的 HTTP REST API。

使用 spring 启动、dropwizard 和 @EnablePrometheusEndpoint 注释。我能够在 /prometheus 端点上生成这样的普罗米修斯指标:

http_client_requests_method_GET_uri_api_v1_objects_status_200_count 3.0
http_client_requests_method_GET_uri_api_v1_objects_status_404_count 1.0

我想在 grafana 中构建一个图表,以显示在 uri api_v1_objects 上使用不同状态代码(每个状态代码一行)对 GET 方法的所有调用。

我应该将状态代码设置为指标的标签吗? io.prometheus simpleclient lib 是否允许使用标签注册 dropwizard 指标?

目前,当我定义图表时,我需要为每个状态代码静态定义一行。对于将来可能出现的新状态代码(500 等),这不是动态的

在此先感谢您的帮助。

奥雷连

"Should I set the status code as a label of the metrics ?"

我认为这是最好的主意。

"Does io.prometheus simpleclient lib allows to register dropwizard metrics with label ?"

问题是 DW 不能很好地处理标签。

如果您正在使用 spring-boot,我真的建议您迁移到 micrometer new metric framewok。它是 spring-boot 2 的默认值,它处理标签和其他元素,因此它比 DW 更适合 promentheus。