简体   繁体   English

如何用spring-boot显示Dropwizard Metrics Servlet?

[英]How to show Dropwizard Metrics Servlet with spring-boot?

I'm using spring-boot-starter-actuator for getting a localhost/metrics endpoint. 我正在使用spring-boot-starter-actuator来获取localhost/metrics端点。

Now I also want to use the dropwizard.metrics and the metrics-servlets dependency. 现在我还想使用dropwizard.metricsmetrics-servlets依赖项。 On their webpage ( https://dropwizard.github.io/metrics/3.1.0/getting-started/ ) it is stated that with this a AdminServet with some kind of admin menu for metrics, healt, threaddump and ping would be created. 在他们的网页上( https://dropwizard.github.io/metrics/3.1.0/getting-started/ ),据说这是一个带有某种指标管理菜单的AdminServet ,会创建healt,threaddump和ping 。

But I don't see that servlet. 但我没有看到那个servlet。 Do I maybe have to register it explicit within spring-boot? 我是否可能必须在spring-boot中明确注册?

I had to instantiate the servlet explicit and provide a servlet mapping path as follows: 我必须显式实例化servlet并提供servlet映射路径,如下所示:

@Bean
public ServletRegistrationBean servletRegistrationBean(){
    return new ServletRegistrationBean(new AdminServlet(),"/metrics/admin/*");
}

In case someone is working with version 5.0.0, these steps were required to get it work: 如果有人使用的是5.0.0版本,则需要执行以下步骤才能使其正常工作:

@Inject
private ServletContext servletContext;

@Inject
private MetricRegistry metricRegistry;

@Inject
private HealthCheckRegistry healthCheckRegistry;

@Bean
public ServletRegistrationBean<Servlet> servletRegistrationBean(){
    servletContext.setAttribute(MetricsServlet.METRICS_REGISTRY,
        metricRegistry);
    servletContext.setAttribute(HealthCheckServlet.HEALTH_CHECK_REGISTRY,
        healthCheckRegistry);

    return new ServletRegistrationBean<>(new AdminServlet(), "/metrics/*");
}

Source: https://stackoverflow.com/a/41382649/1047418 资料来源: https//stackoverflow.com/a/41382649/1047418

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将spring-boot指标保存为日志? - How to persist spring-boot metrics as log? Dropwizard指标注释在Spring Boot 1.5中不起作用 - Dropwizard metrics annotations are not working in Spring Boot 1.5 如何从 spring-boot 千分尺检索指标 - How to retrieve metrics from spring-boot micrometer 如何在 Spring-Boot 中注册启用了“异步支持”的 servlet? - How to register a servlet with enabled "async-supported" in Spring-Boot? 如何像在 web.xml 中一样配置 spring-boot servlet? - How to configure spring-boot servlet like in web.xml? 如何在Spring Boot应用程序中配置HikariCP和Dropwizard / Coda-Hale指标 - How do I configure HikariCP and Dropwizard/Coda-Hale metrics in Spring Boot application 如何自动将 Dropwizard Metrics @Timed 添加到 spring 启动应用程序中的所有 API 方法中? - How to automatically add Dropwizard Metrics @Timed into all APIs method in spring boot application? 如何使用千分尺指定我想要在spring-boot中使用的度量标准的白名单 - How to specify a whitelist of the metrics I want to use in spring-boot with micrometer 您如何配置prometheus.yml文件以在Spring-Boot应用程序中收集Prometheus指标? - How do you configure prometheus.yml file to collect Prometheus metrics in a Spring-Boot application? Java中Spring-Boot微服务的计算监控指标 - Computing Monitoring metrics of Spring-Boot Micro-Service in Java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM