Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to create jmx subdomains?

Tags:

java

jmx

I'm experimenting with dynamically creating mbeans, which represent existing objects created by a framework used in my application. These objects exist in a conceptual hierarchy, like a folder hierarchy. If I just create the mbeans with their associated folder path, I end up with a big domain with lots of objects.

It would be very nice if my JMX viewer (presently VisualVM) could see "subfolders" of the domain associated with the folder hierarchy of these objects.

Is there some way to specify the domain or name property of the mbean so that the JMX viewer would see a hierarchy of these objects, instead of just a big flat list?

like image 939
David M. Karr Avatar asked Dec 18 '13 22:12

David M. Karr


1 Answers

Is there some way to specify the domain or name property of the mbean so that the JMX viewer would see a hierarchy of these objects, instead of just a big flat list?

Yes there is. You can either specify a different domain in your ObjectName and/or you can specify folders as X=Y before the name=... portion of the name. For example:

... = new ObjectName("foo.com:00=folder,01=subFolder,name=SomeBean");

This will create the SomeBean managed JMX bean. It will show up under the foo.com top-level domain folder. Inside of foo.com will be a folder named folder and within that, a sub-folder named subFolder. See the below image from jconsole:

enter image description here

The full ObjectName of the bean is visible to the right. I use the 00=folder,01=subfolder folder names convention. I'm not sure if the numbers are at all visible but the order is critical. The 00 name (in this example folder) is the folder under the domain. The 01 name is the folder inside of the 00 folder (in this example subfolder). There is no limit to the number of sub-folders.

If you want another folder at the same level as folder then you would just use a different 00 name:

... = new ObjectName("foo.com:00=folder2,name=AnotherBean");

As an aside, you might want to look at my SimpleJMX package which does all of the JMX heavy lifting for you. Here's the example program for your enjoyment. With SimpleJMX you use the folderNames annotation field to specify the folders:

@JmxResource(domainName = "j256.com", folderNames = { "counters" },
    beanName = "RuntimeCounter")

This generates the ObjectName of "j256.com:00=counters,name=RuntimeCounter".

like image 113
Gray Avatar answered Sep 24 '22 02:09

Gray