From 0a6c635f5e33d80a610465ac899d5ac871ed06d6 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Thu, 13 Nov 2014 13:58:58 -0800 Subject: [PATCH] Use getMaxActiveSessions() in Tomcat metrics Replace the getMaxActive() call with getMaxActiveSessions(). Fixes gh-1902 --- .../boot/actuate/endpoint/TomcatPublicMetrics.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/TomcatPublicMetrics.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/TomcatPublicMetrics.java index 6c28dc5940..97e8ba596d 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/TomcatPublicMetrics.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/TomcatPublicMetrics.java @@ -24,6 +24,7 @@ import java.util.List; import org.apache.catalina.Container; import org.apache.catalina.Context; import org.apache.catalina.Manager; +import org.apache.catalina.session.ManagerBase; import org.springframework.beans.BeansException; import org.springframework.boot.actuate.metrics.Metric; import org.springframework.boot.context.embedded.EmbeddedServletContainer; @@ -74,12 +75,18 @@ public class TomcatPublicMetrics implements PublicMetrics, ApplicationContextAwa private Collection> metrics(Manager manager) { List> metrics = new ArrayList>(2); - metrics.add(new Metric("httpsessions.max", manager.getMaxActive())); - metrics.add(new Metric("httpsessions.active", manager - .getActiveSessions())); + if (manager instanceof ManagerBase) { + addMetric(metrics, "httpsessions.max", + ((ManagerBase) manager).getMaxActiveSessions()); + } + addMetric(metrics, "httpsessions.active", manager.getActiveSessions()); return metrics; } + private void addMetric(List> metrics, String name, Integer value) { + metrics.add(new Metric(name, value)); + } + @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {