Jolokia Java Client - return List of MBean Names

classic Classic list List threaded Threaded
13 messages Options
papicella papicella
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Jolokia Java Client - return List of MBean Names

Hi,

Is their a way using the java client api to get a List of all the MBeans much like you can using the JMX api directly?

For example I have the following.

J4pClient client = new J4pClient("http://localhost:8778/jolokia");

What method could I use to get back a List of all the MBeans available at this point using the java client api directly?

I can easily get the information I need once I have the MBean name as follows BUT a List of MBeans is what I need prior to actually query the Mbean I am interested in.

eg:

        J4pReadRequest request =
                new J4pReadRequest("java.lang:type=Memory", "HeapMemoryUsage");
        J4pReadResponse response = client.execute(request);
        Map<String,Object> attributes = response.getValue();

Thanks in advance..
roland roland
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Jolokia Java Client - return List of MBean Names

Have a look at J4pListRequest.

It's all explained in the reference manual

ciao ...
... roland
... roland
papicella papicella
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Jolokia Java Client - return List of MBean Names

Hi,

Thanks I was able to gte that to work as follows

        J4pListRequest listRequest = new J4pListRequest("GemFire*");
        J4pListResponse listResponse = client.execute(listRequest);

When I get the name of the Mbean back for some reason it strips out the "GemFire" path , is their a reason for that?

eg:

member=server2,type=Member
member=server1,name=/demoRegion,service=Region,type=Member

Rather it return this if I can :

GemFire:member=server2,type=Member
GemFire:member=server1,name=/demoRegion,service=Region,type=Member
roland roland
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Jolokia Java Client - return List of MBean Names

From the reference manual:

J4pListRequest and J4pListResponse
For obtaining meta data on MBeans a J4pListRequest should be used. It can be used with a inner path to obtain only a subtree of the response, otherwise the whole tree as described in Section 6.2.5.3, “List response” is returned. With the query parameter maxDepth can be used to restrict the depth of returned tree.

The single value of a J4pListResponse is a tree (or subtree) as a JSON object, which has the format described in Section 6.2.5.3, “List response”.
Since you use a path here ("Gemfire") only the remaining subtree is returned. If you are looking only for MBeanName, maybe J4pSearchRequest is more suitable for you ?

... roland
papicella papicella
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Jolokia Java Client - return List of MBean Names

Hi,

yep that's exactly what I was after, so thank you very much

        J4pSearchRequest searchRequest = new J4pSearchRequest("");
        J4pSearchResponse searchResponse = client.execute(searchRequest);

        List<String> mbeanNames = searchResponse.getMBeanNames();

        System.out.println("Size of Mbean list = " + mbeanNames.size() + "\n");

        for (String mbean: mbeanNames)
        {
            System.out.println(mbean);
        }

Output:

GemFire:member=localhost(99878)<v0>-25800,name=/SYS,service=Region,type=Member
GemFireXD:group=MYGROUP,member=localhost(99895)<v1>-63289,service=Table,table=APP.PRODUCTS,type=Member
GemFire:member=localhost(99895)<v1>-63289,name=/SYS,service=Region,type=Member
Tomcat:context=/pulse,host=localhost,name=NonLoginAuthenticator,type=Valve
GemFireXD:service=Table,table=APP.PAYMENTS,type=Aggregate
....
papicella papicella
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Jolokia Java Client - return List of MBean Names

Hi,

Using J4pSearchRequest , how can I filter only the Mbeans I want to see. The code below throws an exception as follows. Using an empty string returns me all mbeans, what exactly is the mbeanpattern string meant to look like?

J4pSearchRequest searchRequest = new J4pSearchRequest("GemFire:");

Exception in thread "main" javax.management.MalformedObjectNameException: Key properties cannot be empty
        at javax.management.ObjectName.construct(ObjectName.java:483)
        at javax.management.ObjectName.<init>(ObjectName.java:1382)
        at org.jolokia.client.request.J4pSearchRequest.<init>(J4pSearchRequest.java:69)
        at org.jolokia.client.request.J4pSearchRequest.<init>(J4pSearchRequest.java:58)
        at apples.jmx.MemoryDemo.main(MemoryDemo.java:17)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Maria Maria
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Jolokia Java Client - return List of MBean Names

In reply to this post by papicella
Hi! How do you build a path out of the information you get? I want to receive the JSON file with data, but I can't find out how to build the right path.
For example, I've got:
org.apache.camel:context=services.camel,name=JmsProducer(0x315c9200),type=producers
org.apache.camel:context=services.camel,name="doTry37",type=processors

When I try it out by http://localhost:8080/jolokia/read/org.apache.camel:context=services.camel/name="doTry37"/type=processors it doesn't work :( What am I doing wrong?
roland roland
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Jolokia Java Client - return List of MBean Names

In reply to this post by papicella
You can use wildcards as specified in the docs to ObjectName --> http://docs.oracle.com/javase/7/docs/api/javax/management/ObjectName.html

I.e. for your case, you can try "GemFire:*", or "GemFire:type=Bla,*" or so ....
... roland
roland roland
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Jolokia Java Client - return List of MBean Names

In reply to this post by Maria
Hi Maria,

the path applies only on the value of an attribute, not the MBean name. In your case you simply need to specify the whole MBean Name:  

http://localhost:8080/jolokia/read/org.apache.camel:context=services.camel,name="doTry37",type=processors

(with plain ","s). Then on the next layer you can specify the attribute you want to read and only after this you can apply a path to dive into the value itself.

'hope this makes sense ;-)

... roland
... roland
Maria Maria
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Jolokia Java Client - return List of MBean Names

Thank you very much :) Maybe one more strange question:
Does the Jolokia give information about the time when server was started? If so, how can the request look like (maybe the name of MBean or some other parameter)? Or it depends?
roland roland
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Jolokia Java Client - return List of MBean Names

That's easy. You find in the MBean "java.lang:type=Runtime" the attribute "Uptime" which gives the time in milliseconds.
... roland
Maria Maria
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Jolokia Java Client - return List of MBean Names

Thanks a lot. You're the best! :)
zhaiyuyong zhaiyuyong
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Jolokia Java Client - return List of MBean Names

In reply to this post by roland
Loading...