Commons Dbcp
  1. Commons Dbcp
  2. DBCP-292

Adds an mbean for exposing metrics around a BasicDataSource via JMX

    Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.2.2
    • Fix Version/s: 2.0
    • Labels:
      None

      Description

      The attached patch adds an mbean that exposes the following metrics of a BasicDataSource via jmx: numActive, numIdle, maxActive, maxIdle, minIdle & maxWait.

      I have put it in a new package: org.apache.commons.dbcp.management but feel free to put it in any package you see fit.

      If using Spring the bean can be configured a little something like this:
      <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
      ...
      </bean>

      <bean id="dataSourceMBean" class="org.apache.commons.dbcp.management.BasicDataSourceMBean">
      <constructor-arg ref="dataSource"/>
      </bean>

      <bean id="mbeanExporter" class="org.springframework.jmx.export.MBeanExporter">
      <property name="beans">
      <map>
      <entry key="DBCP:name=dataSource" value-ref="dataSourceMBean"/>
      </map>
      </property>
      </bean>

        Activity

        Hide
        Karl Palsson added a comment -

        Ég hef látið af störfum hjá Vodafone, vinsamlegast hafið samband við Fannar Örn Þorbjörnsson, fannarth@vodafone.is<fannarth@vodafone.is>

        Kv.
        Karl Jóhann Pálsson

        Show
        Karl Palsson added a comment - Ég hef látið af störfum hjá Vodafone, vinsamlegast hafið samband við Fannar Örn Þorbjörnsson, fannarth@vodafone.is< fannarth@vodafone.is > Kv. Karl Jóhann Pálsson
        Hide
        Mark Thomas added a comment -

        It has taken a while but this has now been fixed. In addition to making the BasicDataSource configuration properties available, the connection pool and any statement pools are also available. Combined with the JMX improvements in Pool2 you can now drill down to the point where you can see exactly which statements are in the statement pool, the time the statement was created, the last time it was borrowed etc.

        Show
        Mark Thomas added a comment - It has taken a while but this has now been fixed. In addition to making the BasicDataSource configuration properties available, the connection pool and any statement pools are also available. Combined with the JMX improvements in Pool2 you can now drill down to the point where you can see exactly which statements are in the statement pool, the time the statement was created, the last time it was borrowed etc.
        Hide
        Cyrille Le Clerc added a comment - - edited

        For those who are using Spring, we packaged a JMX enabled extension of DBCP BasicDataSource at Google Code - XebiaManagementExtras - ManagedBasicDataSource. A Spring XML namespace configuration allows a compact datasource declaration looking like:

        <beans ...>
        
           <!-- MBeanExporter is in charge of registering the DBCP DataSource JMX MBean -->
           <context:mbean-export />
        
           <management:dbcp-datasource id="myDataSource">
              <management:url value="jdbc:h2:mem:dbcp-test" />
              <management:driver-class-name value="org.h2.Driver" />
              <management:username value="sa" />
              <management:password value="" />
              <management:max-active value="10" />
              <!-- ... any other useful configuration param -->
           </management:dbcp-datasource>
        
        </beans>
        

        The associated JMX MBean exposes :

        • Monitoring indicators : NumActive and NumIdle,
        • Read / write configuration parameters to tune the datasource at runtime: MaxActive, MaxIdle, MinIdle and MaxWait,
        • Read only parameters to ease controls: Url, Username and DefaultAutoCommit.
        Show
        Cyrille Le Clerc added a comment - - edited For those who are using Spring, we packaged a JMX enabled extension of DBCP BasicDataSource at Google Code - XebiaManagementExtras - ManagedBasicDataSource . A Spring XML namespace configuration allows a compact datasource declaration looking like: <beans ...> <!-- MBeanExporter is in charge of registering the DBCP DataSource JMX MBean --> <context:mbean-export /> <management:dbcp-datasource id= "myDataSource" > <management:url value= "jdbc:h2:mem:dbcp-test" /> <management:driver-class-name value= "org.h2.Driver" /> <management:username value= "sa" /> <management:password value="" /> <management:max-active value= "10" /> <!-- ... any other useful configuration param --> </management:dbcp-datasource> </beans> The associated JMX MBean exposes : Monitoring indicators : NumActive and NumIdle, Read / write configuration parameters to tune the datasource at runtime: MaxActive, MaxIdle, MinIdle and MaxWait, Read only parameters to ease controls: Url, Username and DefaultAutoCommit.
        Hide
        Julien Nicoulaud added a comment - - edited

        I shared my BasicDataSource mbean wrapper here for those who don't use Spring.

        Show
        Julien Nicoulaud added a comment - - edited I shared my BasicDataSource mbean wrapper here for those who don't use Spring.
        Hide
        Julien Nicoulaud added a comment -

        I agree we need a mbean for BasicDataSource, but it should not rely on Spring....

        Show
        Julien Nicoulaud added a comment - I agree we need a mbean for BasicDataSource, but it should not rely on Spring....
        Hide
        Alexandru Ionita added a comment - - edited

        When registering the bean org.apache.commons.dbcp.BasicDataSource directly into Spring's MBeanExporter, you get the bean registered in the JMX stack.

        What I have observed is that by each Refresh button hit in the JMX jconsole, the NumActive is increased with 2 !!! Basically, the jconsole is consuming two connections from the pool (don't know why) for each refresh without releasing them.

        Show
        Alexandru Ionita added a comment - - edited When registering the bean org.apache.commons.dbcp.BasicDataSource directly into Spring's MBeanExporter, you get the bean registered in the JMX stack. What I have observed is that by each Refresh button hit in the JMX jconsole, the NumActive is increased with 2 !!! Basically, the jconsole is consuming two connections from the pool (don't know why) for each refresh without releasing them.
        Hide
        Karl Palsson added a comment -

        If you're using spring, you don't even need this patch, you can directly register the datasource itself as an mbean. All this patch adds is "synchronised" around all the methods, which is arguably not essential.

        If you're not using spring, then yes, you still need something to register the beans for you.

        Show
        Karl Palsson added a comment - If you're using spring, you don't even need this patch, you can directly register the datasource itself as an mbean. All this patch adds is "synchronised" around all the methods, which is arguably not essential. If you're not using spring, then yes, you still need something to register the beans for you.
        Hide
        Mark Thomas added a comment -

        Gut instinct is that this will raise enough implementation questions that we'll need to push it to 1.4. Happy to pull it forward to 1.3 if ready in time.

        Show
        Mark Thomas added a comment - Gut instinct is that this will raise enough implementation questions that we'll need to push it to 1.4. Happy to pull it forward to 1.3 if ready in time.
        Hide
        Mark Thomas added a comment -

        Big +1 to exposing the connection pool via JMX.

        We can't rely on Spring being present to register this MBean. The patch needs to be extended to register the MBean when the pool is created.

        Show
        Mark Thomas added a comment - Big +1 to exposing the connection pool via JMX. We can't rely on Spring being present to register this MBean. The patch needs to be extended to register the MBean when the pool is created.

          People

          • Assignee:
            Unassigned
            Reporter:
            David Horne
          • Votes:
            3 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development