如何监控c3p0连接

发布于 2024-09-30 17:12:51 字数 506 浏览 5 评论 0原文

我在我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

兮子 2024-10-07 17:12:51

您可以通过 JMX 监控连接池。从文档中:

通过 JMX 配置和管理 c3p0

如果 JMX 库和 JMX
MBeanServer 可在您的
环境(它们包含在 JDK 中
1.5 及更高版本),您可以通过以下方式检查和配置您的 c3p0 数据源
JMX 管理工具(例如
jconsole,与 jdk 1.5 捆绑)。你
会发现c3p0注册了MBeans
com.mchange.v2.c3p0 下,其中一个
有关图书馆的统计数据
整个(称为C3P0Registry),和一个
您的每个 PooledDataSource 的 MBean
部署。您可以查看并修改您的
数据源的配置属性,
跟踪连接的活动,
语句、线程池、以及重置
池和数据源通过
PooledDataSource MBean。 (您可以
希望查看 API 文档
PooledDataSource 用于
可用的文档
操作。)

顺便说一句,Nagios 似乎有 JMX 插件,您不必被迫使用 JSP。

You can monitor your connection pool(s) via JMX. From the documentation:

Configuring and Managing c3p0 via JMX

If JMX libraries and a JMX
MBeanServer are available in your
environment (they are include in JDK
1.5 and above), you can inspect and configure your c3p0 datasources via a
JMX administration tool (such as
jconsole, bundled with jdk 1.5). You
will find that c3p0 registers MBeans
under com.mchange.v2.c3p0, one with
statistics about the library as a
whole (called C3P0Registry), and an
MBean for each PooledDataSource you
deploy. You can view and modify your
DataSource's configuration properties,
track the activity of Connection,
Statement, and Thread pools, and reset
pools and DataSources via the
PooledDataSource MBean. (You may
wish to view the API docs of
PooledDataSource for
documentation of the available
operations.)

By the way, there seem to be JMX plugins for Nagios, you're not forced to use a JSP.

宁愿没拥抱 2024-10-07 17:12:51

您可以像这样使用 Icinga/Nagios 进行监控。

  1. 从谷歌代码下载 JMXQuery。您需要像这样查看修订版 18。

    svn checkout -r 18 http://jmxquery.googlecode.com/svn/trunk/ jmxquery-read-only

  2. 下载此补丁。 c3p0 通配符补丁< /p>

  3. < p>使用此命令修补源代码:(确保您位于 jmxquery-read-only/src/main 目录中)

    patch -p0 -i wildcard_patch.diff

  4. 现在下载Apache Maven 并使用此命令提取它

    tar -zxvf apache-maven-*-bin.tar.gz

  5. 现在 cd 进入 jmxquery-read-only 文件夹并运行以下命令(假设 apache maven 和 jmxquery 位于同一文件夹中)

    ../apache-maven-*/bin/mvncompile

  6. 然后运行以下命令:

    ../apache-maven-3.0.3/bin/mvn package

  7. 现在你应该已经生成了一个 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.

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

  2. Download this patch. wildcard patch for c3p0

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

  4. now download Apache Maven and extract it using this command

    tar -zxvf apache-maven-*-bin.tar.gz

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

  6. then run the following command:

    ../apache-maven-3.0.3/bin/mvn package

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文