【问题标题】:Odd response from actuator/metrics/http.server.requests来自 actuator/metrics/http.server.requests 的奇怪响应
【发布时间】:2020-01-31 09:21:57
【问题描述】:

我收到了来自 /actuator/metrics/http.server.requests 的奇怪响应

{"name":"http.server.requests","baseUnit":"seconds","measurements": 
[{"statistic":"COUNT","value":2.0},{"statistic":"TOTAL_TIME","value":0.325170155}, 
{"statistic":"MAX","value":0.250113973}],"availableTags": 
[{"tag":"requiredMetricName","values":["http.server.requests"]}]}

而且所有标签都不起作用

例如

/actuator/metrics/http.server.requests?tag=status:200

得到 404

我用的是 Spring Boot 2

 implementation 'org.springframework.boot:spring-boot-starter-actuator'

我有

 public static void main(String[] args) {

    SpringApplication application = new SpringApplication(Application.class);

    Properties properties = new Properties();
    properties.put("management.metrics.web.server.auto-time-requests", true);
    properties.put("management.endpoints.web.exposure.include", "*");
    application.setDefaultProperties(properties);

    application.run(args);
}

【问题讨论】:

  • http.server.requests是如何生成的?你在使用 Spring MVC、Webflux 吗?
  • 我需要对 WebMvcConfigurer 做些什么吗?实现 'org.springframework.boot:spring-boot-starter-web'

标签: spring spring-boot spring-boot-actuator


【解决方案1】:

看起来我有多余的豆子。这就是原因

@Bean
public WebMvcTagsProvider webMvcTagsProvider() {
    return new WebMvcTagsProvider() {
        @Override
        public Iterable<Tag> getTags(HttpServletRequest request, HttpServletResponse response, Object handler, Throwable exception) {
            return ((Map<String, String>) request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE))
                    .entrySet()
                    .stream()
                    .map(entry -> new ImmutableTag(entry.getKey(), entry.getValue()))
                    .collect(Collectors.toList());
        }

        @Override
        public Iterable<Tag> getLongRequestTags(HttpServletRequest request, Object handler) {
            return new ArrayList<>();
        }
    };
}

【讨论】:

    猜你喜欢
    • 2019-06-21
    • 1970-01-01
    • 1970-01-01
    • 2021-01-24
    • 1970-01-01
    • 1970-01-01
    • 2012-11-02
    • 2020-12-04
    • 2023-03-12
    相关资源
    最近更新 更多