如何监控c3p0连接
我在我的 JBoss war 中使用 Hibernate,使用 c3p0 进行连接池,两者都在我的类路径中的 hibernate.cfg.xml 配置文件中配置,
<property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
我已经看到 server.log 生成了包含有关连接池的有趣信息的行:
DEBUG [com. mchange.v2.resourcepool.BasicResourcePool] 跟踪 com.mchange.v2.resourcepool.BasicResourcePool@63f5e4b6 [托管:10,未使用:9,排除:0]
对于我的监控池(我正在使用 nagios)我想提供一个JSP 告诉您有多少连接正在使用以及有多少连接是空闲的,如日志文件所示。
我如何询问 c3p0 有多少托管连接和未使用连接?
I am using Hibernate in my JBoss war, using c3p0 for connection pooling, both configured within a hibernate.cfg.xml config file in my classpath
<property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
I've seen server.log generates lines with interesting information about the connection pool:
DEBUG [com.mchange.v2.resourcepool.BasicResourcePool] trace com.mchange.v2.resourcepool.BasicResourcePool@63f5e4b6 [managed: 10, unused: 9, excluded: 0]
For my monitoring pool (I am using nagios) I'd like to provide a JSP telling how many connections are being used and how many are free, as the log file says.
How can I ask c3p0 how many managed and unused connections are there?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过 JMX 监控连接池。从文档中:
顺便说一句,Nagios 似乎有 JMX 插件,您不必被迫使用 JSP。
You can monitor your connection pool(s) via JMX. From the documentation:
By the way, there seem to be JMX plugins for Nagios, you're not forced to use a JSP.
您可以像这样使用 Icinga/Nagios 进行监控。
从谷歌代码下载 JMXQuery。您需要像这样查看修订版 18。
svn checkout -r 18 http://jmxquery.googlecode.com/svn/trunk/ jmxquery-read-only
下载此补丁。 c3p0 通配符补丁< /p>
patch -p0 -i wildcard_patch.diff
现在下载Apache Maven 并使用此命令提取它
tar -zxvf apache-maven-*-bin.tar.gz
现在 cd 进入 jmxquery-read-only 文件夹并运行以下命令(假设 apache maven 和 jmxquery 位于同一文件夹中)
../apache-maven-*/bin/mvncompile
然后运行以下命令:
../apache-maven-3.0.3/bin/mvn package
现在你应该已经生成了一个 jmxquery.jar 文件,你可以用它来查询 c3p0 连接池,如下所示:(check_jmx 文件可以通过从 google code 下载 jmxquery 代码来获取像平常一样使用 此链接)
check_jmx -U 服务:jmx:rmi:///jndi/rmi://localhost:1090/jmxrmi -O com.mchange.v2.c3p0:type=PooledDataSource* -N 1 -A numBusyConnections - w 50 -c 100
You can monitor with Icinga/Nagios like this.
Download JMXQuery from google code. You will need to check out revision 18 like so.
svn checkout -r 18 http://jmxquery.googlecode.com/svn/trunk/ jmxquery-read-only
Download this patch. wildcard patch for c3p0
use this command to patch the source code: (make sure you are in the jmxquery-read-only/src/main directory)
patch -p0 -i wildcard_patch.diff
now download Apache Maven and extract it using this command
tar -zxvf apache-maven-*-bin.tar.gz
now cd into the jmxquery-read-only folder and run the following command (assuming the apache maven and the jmxquery are in the same folder)
../apache-maven-*/bin/mvn compile
then run the following command:
../apache-maven-3.0.3/bin/mvn package
now you should have produced a jmxquery.jar file that you can use to query the c3p0 connection pool like so: (the check_jmx file can be obtained from just downloading the jmxquery code from the google code site like normal. using this link)
check_jmx -U service:jmx:rmi:///jndi/rmi://localhost:1090/jmxrmi -O com.mchange.v2.c3p0:type=PooledDataSource* -N 1 -A numBusyConnections -w 50 -c 100