[英]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.metrics
和metrics-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.