Search code examples
glassfishjvmjconsolejolokia

Jolokia Java client


I´m newbie at JMX. I developped a Web Service, using Glassfish as server. Now I want to monitorize my app;

My first thought was using Jconsole and JVM as monitorizing tool remotly. After continue my research I find this articles:

http://www.javacodegeeks.com/2012/02/client-side-server-monitoring-with.html

Accessing JMX via HTTP alternatives

This suggest that I must use a bridge like Jolokia, which I clearly don´t understant the reason. JConsole + mbeans is not enough?

I continue my research and I created a java project, using their example:

  public static void main(String[] args) throws MalformedObjectNameException, J4pException {
        J4pClient j4pClient = new J4pClient("http://localhost:8080/jolokia/");
        J4pReadRequest req = new J4pReadRequest("java.lang:type=Memory",
                "HeapMemoryUsage");
        J4pReadResponse resp = j4pClient.execute(req);
        Map<String, String> vals = resp.getValue();
        System.out.println("Memory usage: used: " + vals);

    }

It worked, I receive some message, related to my usage memory. But, I don´t know what was the prupose.

What is the best way to monitorize my Web Service?


Solution

  • I recommend using JVisualVM. It's really easy to use and gives great information. Just start you application and then start JVisualVM and it will detect the running java app. You can click on it to get all kinds of information in graphic form. Use it to monitor memory, threads, garbage collection and to create heap dumps.

    The tool you mentioned Jolokia provides a way to monitor an application with lower impact, but is seems like you will need to do more coding. JVisualVM provides lots of information out of box.

    You may need to consider the performance impact of JVisualVM, but I would not worry about it at first unless your website has a high hit rate. You can also choose what to monitor for lower impact.