spring-projects / spring-session

Spring Session
https://spring.io/projects/spring-session
Apache License 2.0
1.86k stars 1.11k forks source link

Consider providing Micrometer integration #1495

Open vpavic opened 5 years ago

vpavic commented 5 years ago

We could consider exposing some session related metrics using Micrometer.

anessi commented 1 year ago

When enabling Spring Session (e.g. with Redis) on a Spring Boot app using embedded Tomcat one can notice that the tomcat.sessions.* metrics no longer get updated. These values are very useful for monitoring the application. These are the available metrics in tomcat:

tomcat.sessions.active.current
tomcat.sessions.active.max
tomcat.sessions.alive.max
tomcat.sessions.created
tomcat.sessions.expired
tomcat.sessions.rejected

It would be very nice to get similar metrics from Spring Session.


Below two example stack traces for how the tomcat.sessions.created metric is set.

Without Spring Sessions:

createSession:725, ManagerBase (org.apache.catalina.session)
doGetSession:3093, Request (org.apache.catalina.connector)
getSession:2493, Request (org.apache.catalina.connector)
getSession:908, RequestFacade (org.apache.catalina.connector)
getSession:920, RequestFacade (org.apache.catalina.connector)
getSession:249, HttpServletRequestWrapper (javax.servlet.http)
...
doRequest:193, LoginServlet (xxxxxx.servlet)
doGet:53, BaseServlet (xxxxxx.servlet)
service:645, HttpServlet (javax.servlet.http)
...

With Spring Session enabled (spring-session-data-redis:2.6.0):

createSession:509, RedisIndexedSessionRepository (org.springframework.session.data.redis)
createSession:251, RedisIndexedSessionRepository (org.springframework.session.data.redis)
getSession:323, SessionRepositoryFilter$SessionRepositoryRequestWrapper (org.springframework.session.web.http)
getSession:332, SessionRepositoryFilter$SessionRepositoryRequestWrapper (org.springframework.session.web.http)
getSession:193, SessionRepositoryFilter$SessionRepositoryRequestWrapper (org.springframework.session.web.http)
getSession:249, HttpServletRequestWrapper (javax.servlet.http)
...
doRequest:193, LoginServlet (xxxxxx.servlet)
doGet:53, BaseServlet (xxxxxx.servlet)
service:645, HttpServlet (javax.servlet.http)

The number of created sessions provided by the metric tomcat.sessions.created is stored on the ManagerBase class and retrieved using:

getSessionCounter:944, ManagerBase (org.apache.catalina.session)
applyAsDouble:-1, 1596426482 (io.micrometer.core.instrument.binder.tomcat.TomcatMetrics$$Lambda$1376)
count:39, CumulativeFunctionCounter (io.micrometer.core.instrument.cumulative)
get:-1, 49082497 (io.micrometer.core.instrument.FunctionCounter$$Lambda$1546)
getValue:39, Measurement (io.micrometer.core.instrument)
lambda$mergeMeasurements$5:131, MetricsEndpoint (org.springframework.boot.actuate.metrics)
...
accept:-1, 1871920265 (org.springframework.boot.actuate.metrics.MetricsEndpoint$$Lambda$1545)
...