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
}
}
} catch (IndexOutOfBoundsException e) {
logger.log(FINE, "", e);
Copy link
Contributor

Choose a reason for hiding this comment

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

Really? Maybe it would be better to clone the list and then use just foreach.

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 know it's not nice. But I suspect this situation happens when the list is modified in parallel. And when a probe is removed, we don't want to execute it, do we?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or, actually, I didn't realize that a probe can be removed also from the middle. So you are right. I'll do as you suggest. It doesn't matter if the probe is execute a few moments after it was removed.

<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 ...

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
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