我使用 properties{
minIdle = 5
maxIdle = 25
maxWait = 10000
timeBetweenEvictionRunsMillis = 5000
minEvictableIdleTimeMillis = 60000
validationQuery = "SELECT 1"
validationQueryTimeout = 3
testOnBorrow = true
testWhileIdle = true
testOnReturn = false
defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED
}
获取spring-boot-starter-actuator
端点。
现在我还想使用localhost/metrics
和dropwizard.metrics
依赖项。在他们的网页(https://dropwizard.github.io/metrics/3.1.0/getting-started/)上声明,metrics-servlets
带有某种指标管理菜单,会创建健康,线程转储和ping。
但我没有看到那个servlet。我是否可能必须在spring-boot中明确注册?
答案 0 :(得分:5)
我必须显式地实例化servlet并提供servlet映射路径,如下所示:
@Bean
public ServletRegistrationBean servletRegistrationBean(){
return new ServletRegistrationBean(new AdminServlet(),"/metrics/admin/*");
}
答案 1 :(得分:1)
如果有人正在使用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/*");
}