2
votes

I am using an Oracle connection pool by using the following Spring configuration for my datasource:

  <bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource">
    <property name="connectionCachingEnabled" value="true" />
    <property name="URL" value="myUrl" />
    <property name="user" value="myUserName" />
    <property name="password" value="myPassword" />
    <property name="connectionCacheProperties">
        <util:properties>
            <prop key="InitialLimit">5</prop>
            <prop key="MinLimit">5</prop>
            <prop key="MaxLimit">30</prop>
            <prop key="MaxStatementsLimit">20</prop>
        </util:properties>
    </property>
</bean>

I would like to expose the statistics of this pool via JMX so that I can monitor the pool to see how many connections are in the pool, how many are busy, etc.

I am connecting to an Oracle 10g server with the oracle 11.2.0.3.0 jdbc driver.

How do I do this?

2

2 Answers

1
votes

Try this -

MethodNameBasedMBeanInfoAssembler

public class MethodNameBasedMBeanInfoAssembler

Subclass of AbstractReflectiveMBeanInfoAssembler that allows to specify method names to be exposed as MBean operations and attributes. JavaBean getters and setters will automatically be exposed as JMX attributes.

You can supply an array of method names via the managedMethods property. If you have multiple beans and you wish each bean to use a different set of method names, then you can map bean keys (that is the name used to pass the bean to the MBeanExporter) to a list of method names using the methodMappings property.

If you specify values for both methodMappings and managedMethods, Spring will attempt to find method names in the mappings first. If no method names for the bean are found, it will use the method names defined by managedMethods.

For example -

...
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean">
    <property name="locateExistingServerIfPossible" value="true" />
</bean>

<bean id="mbeanExporter" class="org.springframework.jmx.export.MBeanExporter">
   <property name="assembler">
      <bean class="org.springframework.jmx.export.assembler.MethodNameBasedMBeanInfoAssembler">         
         <property name="managedMethods">
         <list>
            <value>getNumActive</value>
            <value>getMaxActive</value>
            <value>getNumIdle</value>
            <value>getMaxIdle</value>
            <value>getMaxWait</value>
            <value>getInitialSize</value>
         </list>
         </property>         
      </bean>
    </property>

    <property name="beans">
       <map>                   
          <entry key="dataSource:name=DataSource" value-ref="dataSource"/>    
       </map>
    </property>

    <property name="server" ref="mbeanServer" />

</bean>
0
votes

For Enabling JMX in Hibernate, EhCache, Quartz, DBCP and Spring Kindly refer the http://nurkiewicz.blogspot.com/2011/12/enabling-jmx-in-hibernate-ehcache-qurtz.html