Monday Oct 13, 2008

JDBC Pool Monitoring using Management Rules

After my basic blog blog about creating and writing mbeans and self management rules, here is a post on how to monitor a certain attribute of a jdbc connection pool using Self Management Rule.
I would take for example, the connection validation failures. The Monitoring framework of glassfish provides statistics on various attributes including an attribute specially for the number of connection validation failures. Here are the steps :


1. First of all, enable the monitoring for JDBC Connection Pool to HIGH from the admin console or from CLI.


2. Create JDBC Connection Pool/JDBC Resource for this exercise : conValPool and jdbc/conval respectively.


3. We would be monitoring the attribute for connection validation failure on this pool conValPool.


4. The objectName for this conValPool for monitoring would be "com.sun.appserv:name=conValPool,type=jdbc–connection–pool,
category=monitor,server=server"
I got this objectName from listing all mbeans and querying the names for conValPool. Note that this mbean is specifically for monitoring this pool since the category is monitor.


5. When i open jconsole and login to it, i see that com.sun.appserv  section, there is a head called conValPool. Under this, we see a server element if we browse down the tree. On the right pane, we can see all the attributes and i would take a note of the attribute with name numconnfailedvalidation–count.
I would use this attribute in my custom mbean event.


6. Create an mbean called ValidationMonitor for getting the value of numconnfailedvalidation–count at any point of time. It would have code that gets the value as follows




MBeanServer server = ManagementFactory.getPlatformMBeanServer();
numConnFailVal = (Long) server.getAttribute(new
    ObjectName("com.sun.appserv:name=conValPool,type=jdbc–connection–pool,
    category=monitor,server=server”) , "numconnfailedvalidation–count";)



I use the getAttribute method on the MBeanServer with the above mentioned ObjectName and the attribute name. The numConnFailVal is the attribute that will be returned whenever this mbean is invoked.


7. Create an mbean called ValidationAction for the action part of the management rule. This action would be triggered every time some threshold is crossed as part of the rule that we are going to create shortly. The action as of now is going to be a simple System.out.println  to the server.log as follows




public class ValidationAction implements NotificationListener,
    com.sun.example.action.ValidationActionMBean {
    public synchronized void handleNotification(Notification notification, Object handback) {
         try {
System.out.println("Validation  Failure Threshold Notification: " +
                       notification);
          } catch(Exception ex) {
          }
     }
}




Note that the action mbean implements the NotificationListener interface.


8. Coming to the part of creating a management rule to hook up this action and event, we log into the admin console and deploy the custom mbeans created above.
Then under the Management Rules link under Configuration, create a new management rule called ValFailRule. Specify the event type as monitor and other values as follows




observed MBean value : user:impl–class–name=com.sun.example.mbeans.ValidationMonitor,
name=validationmonitor,server=server

observedAttribute value : numConnFailVal
Monitor type to Counter
Granularity period to 1000 milliseconds so that every second the rule would check for the numConnFailVal value.
Number type to long since the return value from our mbean is of type long.
Init Threshold value to 2 so after 2 failed validations, the rule is going to write something to the
server log.
Offset to 1
Select the validationaction from the list under Action section for the action mbean name.



9. The management rule is successfully setup and once you have a test running that would change the validation failure values, the rule would play its role. Whenever the numConnFailVal value goes above 2, the following can be seen in the server.log



Validation  Failure Threshold Notification:%javax.management.monitor.MonitorNotification[
 source=com.sun.appserver.selfmanagement:numbertype=long,granularityperiod=1000,offset=1,
monitortype=countermonitor,initthreshold=2,version=3,observedattribute=NumFailValidation,
differencemode=false]
[type=jmx.monitor.counter.threshold][message=]|#]

[#|2008–10–13T18:14:59.683+0530|SEVERE|sun–appserver9.1|
javax.enterprise.system.core.selfmanagement|_ThreadID=30;_ThreadName=Timer7641;
_RequestID=c409bfc3–d0de
43f6a09f5ae1be9f0e51;|Logging selfmanagement event :
monitor:SEVERE:¦#]




SEVERE messages are because the log level was set to SEVERE while the rule was created.


This is just an example of how a JDBC pool monitoring attribute can be observed via mbeans and action taken above a threshold using a management rule. Any other meaningful action could be taken instead of the above.


Hope this is useful. :)

About

shalini_m

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today