Skip to content

Conversation

@OndroMih
Copy link
Contributor

@OndroMih OndroMih commented Oct 25, 2025

Ensures that the reported current thread count and busy thread count is exactly the number of threads reported by the pool. Even if monitoring is started while thread pool is actively processing requests.

A few improvements in Embedded GlassFish to enable monitoring and access it via JMX (it was completely broken before):

  • if the flashlight-agent is already loaded, don't attempt to load it - that would fail on newer Java versions
  • concatenate probe-provider-class-names MANIFEST elements from dependencies, using gmaven plugin script at build time. It references all probes that should be activated

Embedded GlassFish requires running with flashlight-agent on command line with -javaagent:flashlight-agent.jar on newer Java versions as it doesn't contain the agent. Dynamic loading of agent is not a good practice with newer Java versions anyway.

When started with command "enable-monitoring --mbean true", metric will be available via JMX beans:

Example to start Embedded GlassFish with thread pool and http service metrics:

java -javaagent:/path/to/flashlight-agent.jar -jar glassfish-embedded-all.jar 'enable-monitoring --modules thread-pool:http-service'

Or, alternatively, using the following properties in glassfish.properties in the current directory:

configs.config.server-config.monitoring-service.module-monitoring-levels.thread-pool=HIGH
configs.config.server-config.monitoring-service.module-monitoring-levels.http-service=HIGH

And command:

java -javaagent:/path/to/flashlight-agent.jar -jar glassfish-embedded-all.jar

Then in VisualVM (with MBeans extension), in the amx node:

image

If you don't see the amx node, you need to execute the bootAMX operation from VisualVM first (the added test demonstrates how to do that in code):

image

Requires running with flashlight-agent on command line with -javaagent:flashlight-agent.jar
When started with command "enable-monitoring --mbean true", metric will be available via JMX beans
Needed for monitoring, at least in Embedded GlassFish. Otherwise:

java.lang.reflect.InaccessibleObjectException: Unable to make public java.util.Enumeration jdk.internal.loader.BuiltinClassLoader.findResources(java.lang.String) throws java.io.IOException accessible: module java.base does not "exports jdk.internal.loader" to unnamed module @1de0aca6
	at java.base/java.lang.reflect.AccessibleObject.throwInaccessibleObjectException(AccessibleObject.java:391)
	at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:367)
	at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:315)
	at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:203)
	at java.base/java.lang.reflect.Method.setAccessible(Method.java:197)
	at com.sun.enterprise.module.single.ManifestProxy.<init>(ManifestProxy.java:71)
	at com.sun.enterprise.module.single.ProxyModuleDefinition.generate(ProxyModuleDefinition.java:146)
	at com.sun.enterprise.module.single.ProxyModuleDefinition.getManifest(ProxyModuleDefinition.java:134)
	at org.glassfish.admin.monitor.MonitoringBootstrap.addProvider(MonitoringBootstrap.java:298)
@OndroMih OndroMih force-pushed the ondromih-glassfish7-monitoring branch from f7871b9 to 6c3eff8 Compare October 25, 2025 15:50
@OndroMih OndroMih force-pushed the ondromih-glassfish7-monitoring branch 4 times, most recently from d4bdf73 to 28dd44c Compare October 26, 2025 13:52
Disable test for Embedded Web - it doesn't support AMX because it doesn't include glassfish-mbeanserver artifact.
@OndroMih OndroMih force-pushed the ondromih-glassfish7-monitoring branch from 28dd44c to 0a14238 Compare October 26, 2025 13:54
- do not unregister probes when deleting listener, unless it's the last listener
- count busy threads in the monitor and pass info to stats (maybe not necessary)
- catch out of bounds exception in probes, which sometimes happens, probably because of a probe is removed concurrently from the array while iterating through the collection
- global stats updates with the setCurrentThreadCountEvent event
<plugins>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>groovy-maven-plugin</artifactId>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer using java and exec plugin; not sure if it is doable.
The groovy is not so well readable for us and we tend to do evil things: catching exceptions without processing them, closing jars just when their processing doesn't throw exceptions instead of try-with ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was lazy here and asked AI. It couldn't figure out how to do it using Ant. It kept suggesting using exec plugin with a shell script, which obviously wouldn't work on Windows. Then I decided to use Groovy, which works everywhere. Another option would be to create a new maven plugin, but that would have to be a separate project, or part of the buildhelper plugin, which is external and we would have to release it first.

Another option is to create a script in Java and execute it via the exec plugin, maybe that's what you mean. If we can compile it first or execute it directly as a script, then it should work too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried. It's just too complicated. Groovy script is the best option. The only other option is to create a separate maven plugin, because we need to set a maven project property, which is used in another plugin to build the final MANIFEST. And I don't want to bother with a separate Maven plugin. The Groovy script is almost like Java and it's pretty simple.

Also adds tests for it.

Also adds support for a system property glassfish.remote, to run tests against a remote server instead of setting up a local (managed) one and stopping it after tests. This helps in debugging test scenarios.
@OndroMih OndroMih added embedded Relates to the Embedded GlassFish Component: Monitoring Related to GlassFish monitoring, metrics, etc. labels Oct 28, 2025
@OndroMih OndroMih requested a review from a team October 29, 2025 09:15
@OndroMih OndroMih force-pushed the ondromih-glassfish7-monitoring branch from 82cfb22 to 4575b83 Compare October 29, 2025 14:52
Introduced by a previous "fix" :)
@OndroMih OndroMih force-pushed the ondromih-glassfish7-monitoring branch from 4575b83 to dc4c6e7 Compare October 30, 2025 00:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component: Monitoring Related to GlassFish monitoring, metrics, etc. embedded Relates to the Embedded GlassFish

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants