gpt4 book ai didi

java - 如何通过 JMX 公开 Oracle 连接池统计信息?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:06:07 25 4
gpt4 key购买 nike

我通过为我的数据源使用以下 Spring 配置来使用 Oracle 连接池:

  <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>

我想通过 JMX 公开这个池的统计信息,以便我可以监视池以查看池中有多少连接,有多少正忙等。

我正在使用 oracle 11.2.0.3.0 jdbc 驱动程序连接到 Oracle 10g 服务器。

我该怎么做?

最佳答案

试试这个-

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.

例如-

...
<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>

关于java - 如何通过 JMX 公开 Oracle 连接池统计信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21294570/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com