JMX Notification for alerts
August 9, 2014 . Comments
Tags: java, JMX, Monitoring, JVM
With the use of javax.management it is possible to notify other users/ machines about cache eviction or perform alerts for errors or warnings.
The notification on MBeans can effectively used for building self healing systems. Where one server can notify others if it is overloaded so that they can take charge.
In this example we will see how the notification can be used to show alerts when a error happens.
The code below throws errors when a random value is hit simulating a error scenario
I shall be adding these two methods to TimeLapseCounter explained in the previous blog.
These methods enable the counter to notify when a error is triggered in deSerialize method. All the errors generated will be collected in the Notification Listener in our case it would be JConsole/JVisualVM. We can extend it further to provide a warning when a critical method goes out of SLA by triggering it in the TimeLapseCounter.
In the above example I am using the AttributeChangeNotification class to notify on errors and warnings. I would ideally like to extend the Notification class and expose the counters. The down side to that approach is to have my implementation class be part of the class path of the NotificationListener which would not solve the purpose. If not in class path we would receive this warning in JConsole.
Jul 29, 2014 7:42:02 PM ClientNotifForwarder NotifFetcher.fetchOneNotif
WARNING: Failed to deserialize a notification: java.lang.ClassNotFoundException: com.banyan.jmx.notification.LogErrorNotification (no security manager: RMI class loader disabled)
My above implementation would work perfectly in all JMX clients.
This is how the error messages will get displayed in JConsole.
The javax.management package can be used in your application to listen to messages and act accordingly to resolve conflicts. Look for a blog on that soon.
Feel free to comment on the post but keep it clean and on topic.