Question

I want to write app in java which will get info about processes and threads running on Jboss JVM (%cpu usage, memory etc.). I also want to find info about memory usage and other important things in JVM (JBoss). How to write it in pure java?

I know about things like JConsole, but I need to write it by myself. I've found java.lang.managament interface which gives some information about system, memory etc, but not all needed information are provided. For example I'd like to have opportunity read cpu usage (not cpu time) and memory used by every thread. (something like top command in bash, but I need to make it in java).

Any help?

EDIT: Eventually I can use some libraries to get this info.

Was it helpful?

Solution

The JBoss AS 7 provide different management interfaces. All the management interfaces based on the Detyped Management representation (jboss-dmr).

You can implemet a custom Java client with the jboss-dmr library and the jboss-as-controller-client. For an example, see our github repository.

To get information about the JVM and other stuff, you need to implement the following operation:

ModelNode operation = new ModelNode();
operation.get("operation").set("read-resource");
operation.get("recursive").set(true);
operation.get("include-runtime").set(true);
ModelNode address = operation.get("address");
address.add("core-service", "platform-mbean");

Alternatively, you can also use the PlatformMBeanServer:

    //Get a connection to the JBoss AS MBean server on localhost
    String host = "localhost";
    int port = 9999;  // management-native port
    String urlString = "service:jmx:remoting-jmx://" + host + ":" + port;
    JMXServiceURL serviceURL = new JMXServiceURL(urlString);
    JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, null);
    MBeanServerConnection connection = jmxConnector.getMBeanServerConnection();

    //Invoke on the JBoss AS MBean server
    connection.getObjectInstance(new ObjectName("java.lang:type=Threading"));
    //...
    jmxConnector.close();

OTHER TIPS

As stated by Adam, there are several tools to monitor java/jboss resources use, another one is JBoss RHQ.

But if you really need to program it on your own, maybe you'll find some useful information accessing the jboss.system:type=ServerInfo mbean(check its attributes and also the methods: listMemoryPools, listThreadCpuUtilization,listThreadDump ...). You can access them using JMX Console, or programmatically.

You can try Java Melody. It is a very nice tool to monitor Java Applications. check out the tool at the link below

https://code.google.com/p/javamelody/

-Sushitha

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top