Reputation: 6664
What are some of the best practices in designing a JMX MBean? Any examples of ones you feel are especially useful?
Upvotes: 10
Views: 891
Reputation: 272297
Return absolute counts instead of rates. e.g. return total number of db commits, rather than deriving a rate.
By doing this, your clients can monitor and derive rates themselves, over whatever time periods they require. Perhaps more importantly, this protects the clients from missing surges in rates if they only connect infrequently.
If you're using JMX beans primarily via the HTML interface, then there are several practises I follow. The below often means that your JMX bean should wrap an existing bean (as opposed to just JMX-exposing existing methods):
toString()
output can be next to uselesstrim()
it to remove whitespace etc.)The above changes the emphasis from a bean simply exposed via JMX to something approaching a useable admin console.
Upvotes: 6
Reputation: 10288
Do not use JMX for logging so, for example, don't use an MBean function that returns details of all the connections since startup.
One should remember that JMX is meant for monitoring. Meaning - Display only data that is relevant to the current moment.
Upvotes: 1
Reputation: 12782
Make sure that attributes have no side effects and are predictable in operation.
There is nothing worse than an innocent looking attribute that executes a time-consuming (or resource-consuming) operation. I've seen some humdingers in my time..
Upvotes: 3
Reputation: 15767
The first thing that got me with my first JMX bean was return types - it's a lot easier if your methods return Strings - that way your client can easily display the response (I was mainly working with JConsole) - if you don't do this, you get things like com.mycompany.Response@xxxx as a response, which doesn't mean much :)
Upvotes: 4