我可以添加一个新的维度/标签到现有的度量http_server_requests_seconds? &



我有一个使用Prometheus收集指标的Java Spring Boot应用程序。它是一个REST API,一切正常。

默认情况下,Spring提供了一些度量。例如,度量http_server_requests_seconds_count的维度为:
http_server_requests_seconds_count{application="metrics-demo-app", exception="None", instance="host.docker.internal:8080", job="metrics-demo-app", method="GET", outcome="SUCCESS", status="200", uri="/actuator/prometheus"}

维度指的是上面示例中的键/值对(application="metrics-demo-app" exception="None",等)标记。

我可以在这些度量中添加一个新的维度(键/值对)吗?我的想法是,当创建用户的调用失败时,在该度量中插入一些更多的信息。

我知道我可以创建一个新的自定义指标,但我想知道是否有某种方式可以在现有的指标中添加东西。

这可能吗?怎么做呢?

Thanks in advance:D

这是可以做到的,如何在文档中,在这里:https://docs.spring.io/spring-boot/docs/current/reference/html/actuator.html actuator.metrics.supported.system

我的代码是这样结束的:

@Configuration
public class MetricsConfig implements WebMvcTagsProvider {
private final WebMvcTagsProvider delegate = new DefaultWebMvcTagsProvider();
@Override
public Iterable<Tag> getTags(HttpServletRequest request, HttpServletResponse response, Object handler, Throwable exception) {
final String channelId = ServiceContextHolder.getContext().getXItauChannelId();
return Tags.of(this.delegate.getTags(request, response, handler, exception)).and("channelId", channelId);
}
@Override
public Iterable<Tag> getLongRequestTags(HttpServletRequest request, Object handler) {
return null;
}
}

最新更新