Is it possible to access a JVM's JMX server from inside that JVM instance? Or would I have to connect through the standard socket/port remote interface?
+----------------------------------------+ Option 2: Connect
| +---------------------------+ | through sockets like
| | My Notification Listener |+----->----------+ a remote
| | | | | monitor.
| +---------------------------+ | |
| + | |
| Option 1: connect| | |
| to the internal | | |
| JMX server. I'm | | |
| trying to find | | |
| if this is possible. | |
| | | |
| | | |
| A single JVM instance. | | |
| | | |
| +------------+-----v------+--+ | |
| | | GuageMXBean|<-+<--------------+
| | +------------+ | |
| | JMX MXBean Server | |
| +----------------------------+ |
+----------------------------------------+
Context: I'm trying to implement an 'intelligent' system that responds to JVM state, specifically memory usage, shifting between caching working data to disk, and holding it in ram. Setting up a JMX listener seemed more elegant than running a background thread that does something like:
Runtime RTime = Runtime.getRuntime();
while(!shutdown)
{
if((RTime.totalMemory / RTime.maxMemory) > upperThreshold) cachmode = CACHETODISK;
if((RTime.totalMemory / RTime.maxMemory) < lowerThreshold) cachmode = CACHETORAM;
Sleep(1000);
}
Desktop application, if it makes a difference.
This is my first SO post, so any hints on improvement, etc. of the question are welcome.
When the JBoss Server is running, you can get a live view of the server by going to the JMX console application at http://localhost:8080/jmx-console.
A common way to enable local JMX access on these JVMs is to include the -Dcom. sun. management. jmxremote option on the command line when you start the JVM.
You can easily get the platform MBean Server from using this code.
ManagementFactory.getPlatformMBeanServer();
There are lot of useful MBeans for collecting information about the state of the JVM. here is a simple example
List<GarbageCollectorMXBean> gcBeans = ManagementFactory.getGarbageCollectorMXBeans();
// generate heap state report
String report = "";
for (GarbageCollectorMXBean gc : gcBeans) {
report += "\nGC Name : " + gc.getName();
report += "\nCollection count: " + gc.getCollectionCount();
report += "\nCollection Time : " + gc.getCollectionTime() + " milli seconds";
report += "\n";
}
List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();
for (MemoryPoolMXBean pool : memoryPoolMXBeans) {
report += "\nMemory Pool: " + pool.getName();
MemoryUsage usage = pool.getUsage();
report += "\n Max : " + usage.getMax() / 1024000 + "MB";
report += "\n Used: " + usage.getUsed() / 1024000 + "MB";
report += "\n";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With