Lately I was struggling with the JMX configuration of the glassfish application server (version 3.2.1) longer than initially expected. Maybe I should have read the glassfish documentation first but I was kind of lazy and started with trial and error. So if someone else wants to do the same thing here are the problems I faced and the steps to solve them.
In my case I wanted to read out the number of active HTTP sessions of a remote glassfish server using JMX. I started with JConsole to check which concrete JMX beans and attributes are offered by glassfish. I looked up the JMX connection port in the glassfish admin (default port is 8686) and tried to connect to the server:
Connection failed: Connection refused: connect
After a little while I found out that you have to tell glassfish with certain JVM parameters that it should accept remote JMX connections (to make things easy no authentication was activated):
After a restart of the application server the connection with JConsole was successful. I was searching through the beans in JConsole but couldn’t find anything like number of sessions. I figured out that you have to activate the web-container monitoring (level=HIGH) in the glassfish admin to get this data:
After this is activated (no restart is required) you can see the session data of your instance in the glassfish admin:
I thought the same is true now for reading the data with JConsole. Wrong! Still no session data available!?
I found out that glassfish offers this data through a special JMX interface called AppServer Management Extensions (AMX). However there was no amx node shown in JConsole only amx-support. Here you find a nice little button called bootAMX and when you click it the amx node (magically) appears:
This triggers the registration of all AMX MBeans by executing the JMX operation bootAMX on the MBean amx-support:type=boot-amx. However you have to repeat this after each restart of the server to renew the registration. According to the glassfish monitoring reference wiki other possibilities to register these beans are:
- MEJB connection
- JMXConnector client connection
- explicit call to bootAMX()
- AmxPref.getAutoLoad() is true
(I just found this page but did not try any of these options expect explicitly calling bootAMX using JConsole. Maybe some of you have experience how to activate AMX by default for every startup … let me know)
The session data can finally be found under amx/session-mon:
I hope that post could help other glassfish users. Comments are welcome!