Advertise with us

Our eBooks

Monitor JBoss AS with Jolokia

 

Pretty nice. One thing you might need is interacting with the AS MBeans programmatically. There are several options for it (including Javascript). We will use a plain Java Client. In order to use the Jolokia Java API, you need to donwload a few libraries:

Jolokia Client API

And the following dependencies:

So, once downloaded all the required libs, in the following example we will create a minimal Java client which issue a read request on the  HeapMemoryUsage object:


package com.sample;

import org.jolokia.client.*;
import org.jolokia.client.request.*;

import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class JmxClient {

   public static void main(String[] args) throws Exception {
       J4pClient j4pClient = new J4pClient("http://localhost:8080/jolokia/");
       J4pReadRequest req = new J4pReadRequest("java.lang:type=Memory",
                                               "HeapMemoryUsage");
       J4pReadResponse resp = j4pClient.execute(req);
       Map vals = resp.getValue();
       Set set = vals.keySet();
       Iterator i = set.iterator();
       while (i.hasNext()) {
           Object key = i.next();
           System.out.println(key + " = " +vals.get(key));
       }


   }
}

which will produce:

max=518979584
committed=65011712
init=67108864
used=26947208                       
© 2021 mastertheboss.com. All Rights Reserved.

Please publish modules in offcanvas position.