Saving VisualVM information as data
Asked Answered
S

3

5

Using VisaulVM, I'd like to obtain this as data, without image processing algorithms being applied... How can I do that? I think this won't come out of a snapshot.

enter image description here

I am not sure how VisualVM and jVisualVM vary, the naming is sure confusing, but I'm running the Oracle supplied one (Version 1.7.0_80 (Build 150109))

Thanks!

Southwards answered 7/12, 2015 at 15:13 Comment(1)
Isn't there perhaps such an option inside VisualVM?Southwards
N
7

You can use Tracer plugin with various probes. Tracer can export data in CSV, HTML or XML.

Nostoc answered 8/12, 2015 at 17:35 Comment(1)
Can Mbeans be exported too? I see multiple Tracer plugins in my VisualVM installation. Which to pick?Retaliate
N
4

All this information is available through JMX. That's how VisualVM gets the information and you can use the same technology to get it too. First install the VisualVM-MBeans plugin from the Tools menu. This will add another tab titled MBeans where you can see all the available data for your application. You will find the graphed data under java.lang.Memory and java.lang.OperationSystem.

If you're trying to check information for your own process, it's as simple as calling ManagementFactory.getOperatingSystemMXBean().getSystemLoadAverage() and ManagementFactory.getMemoryMXBean().getHeapMemoryUsage(). There are more, but these should get you started.

To get precise CPU usage see: Using OperatingSystemMXBean to get CPU usage

If you want to get information on another process, you'd need some more code. There is a complete answer on Accessing a remote MBean server but basically:

// replace host and port
// not tested, might not work
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://<addr>:<port>");
JMXConnector jmxConnector = JMXConnectorFactory.connect(url);
MBeanServerConnection connection = jmxConnector.getMBeanServerConnection();
OperatingSystemMXBean bean = ManagementFactory.getPlatformMXBean(connection, OperatingSystemMXBean.class);
bean.getSystemLoadAverage();

You will also have to start your Java process with exposed JMX as explained on How to activate JMX on my JVM for access with jconsole? but basically:

-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=9010
-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false

There is also a way to enumerate Java processes running on the local machine and even connect to processes that don't have JMX enabled (though you get less data). If that's what you're looking for, VisualVM Source Code will be a good place to start.

Negotiation answered 8/12, 2015 at 2:5 Comment(2)
Thanks a lot for tying everything together. I guess could be cool having a library taking care of some mundane aspects of this, like efficient data logging, closing rather than losing the file before an abnormal termination, or possibly others stuff I can't think of right now.Southwards
In that last regard, I've asked #34137548 in parallel..Southwards
N
1

To answer your other question about naming:

VisualVM is opensource project hosted at visualvm.java.net and Java VisualVM is stable version of VisualVM with Oracle branding and other small changes. Java VisualVM is distributed in JDK. There is a table where you can find which VisualVM release is the basis for Java VisualVM in respective JDK update.

Nostoc answered 9/12, 2015 at 9:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.