Home » Java » java – How to get last access time of application in WebSphere Liberty Server 19.0.0.11-Exceptionshub

java – How to get last access time of application in WebSphere Liberty Server 19.0.0.11-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

Am developing application in Java 8, JSF, Maven. Build application as war and deploying it in WebSphere Liberty Server 19.0.0.11. I got requirement to get application last access time.? Is there any way to get this detail.?

How to&Answers:

One way you could do that is by watching the vendor_servlet_request_total metric (provided by the mpMetrics-2.x feature). There is a separately labeled time series for each servlet (a time series is a sequence of metric values in chronological order) — by periodically polling the /metrics endpoint, and totalling the values across all servlets you would be able to tell when traffic has stopped.

10:17am

vendor_servlet_request_total{servlet=MyServletA} 100
vendor_servlet_request_total{servlet=MyServletB} 205

10:18am

vendor_servlet_request_total{servlet=MyServletA} 102
vendor_servlet_request_total{servlet=MyServletB} 209

10:19am

vendor_servlet_request_total{servlet=MyServletA} 102
vendor_servlet_request_total{servlet=MyServletB} 209

In the example above, since the servlet request counts didn’t change between 10:18am and 10:19am you can conclude that the last access was before 10:18am.

see https://openliberty.io/docs/ref/general/#metrics-catalog.html for more detail on the available metrics from mpMetrics-2.x.

Answer:

You could probably write a filter that would intercept all requests to the app and update variable that would hold last access , or return that variable value if you would query for that.