Monitor idle/busy connections in C3P0

1,529 views
Skip to first unread message

Toby

unread,
Dec 13, 2012, 5:24:27 AM12/13/12
to javam...@googlegroups.com
Hi,

Any suggestions on how to monitor busy/idle connections in C3P0? I'd like to chart them over time but by default(?) JavaMelody doesn't realize I'm using the connection pool. These stats are available via JMX.

Specifically, I'm trying to work out if the max pool size is set to a sensible number for my app's profile.

Cheers

char...@thelearningbar.com

unread,
Jul 8, 2013, 9:55:21 AM7/8/13
to javam...@googlegroups.com
HI Toby,

There's probably better ways but we use a tool called jmxterm.jar which will allow you to open a tomcat PID and then select a bean and get attributes such as com.mchange.v2.c3p0:type=PooledDataSource and attributes like numBusyConnections.

Cheers,
Charles

evernat

unread,
Jul 8, 2013, 10:10:19 AM7/8/13
to javam...@googlegroups.com, char...@thelearningbar.com
Hi,

Getting the value with jmxterm seems to be the same as using the "External API" of javamelody:
https://code.google.com/p/javamelody/wiki/ExternalAPI
except that you don't have to start a JVM for jmxterm and you only need to make a http call to javamelody.


For example, the following url gets the value of the LoadedClassCount attribute of the ClassLoading MBean in the javamelody demo:
http://demo.javamelody.cloudbees.net/monitoring?jmxValue=java.lang:type=ClassLoading.LoadedClassCount

If C3P0 was used in the application, getting the busy connections would probably have been something like:
http://<host>/<context>/monitoring?jmxValue=com.mchange.v2.c3p0:type=PooledDataSource.numBusyConnections

bye,
Emeric

thomas.e...@googlemail.com

unread,
Oct 26, 2015, 5:36:12 AM10/26/15
to javamelody, char...@thelearningbar.com
Hi Evernat,

Apologies for resurrecting an old thread, but my question is directly related. I'm trying to use this:

http://<host>/<context>/monitoring?jmxValue=com.mchange.v2.c3p0:type=PooledDataSource.numBusyConnections

but am having problems due to having more than one datasource in my configuration, each tend to look like com.mchange.v2.c3p0:type=PooledDataSource,identityToken=2rwamz9c19cpp43706039|78d50a3c,name=ccsDataSource in jconsole, but trying to use, for instance: http://<host>/<context>/monitoring?jmxValue=com.mchange.v2.c3p0:type=PooledDataSource,identityToken=2rwamz9c19cpp43706039|78d50a3c,name=ccsDataSource.numBusyConnections throws 

java.lang.IllegalArgumentException: com.mchange.v2.c3p0:type=PooledDataSource,identityToken=2rwamz9c19cpp43706039

caused by 

javax.management.MalformedObjectNameException: Key properties cannot be empty

I attempted to encode the ID string, but it won't recognise the encoding for | for whatever reason. Are you aware of another/better way to obtain this property via javamelody? I realise I can just define my own jmx beans and get the data out internally, but for a variety of reasons, it will be better if I can use the javamelody API.

Thanks,

Thomas

evernat

unread,
Oct 26, 2015, 11:26:05 AM10/26/15
to javamelody, char...@thelearningbar.com, thomas.e...@googlemail.com
Hi Thomas,

The '|' character (pipe) is currently not supported in the jmxValue parameter, for the name of a jmx bean (because it is understood by javamelody as a separator between several jmx names when you want to get several values).

See https://github.com/javamelody/javamelody/blob/master/javamelody-core/src/main/java/net/bull/javamelody/MBeans.java#L374

Emeric

thomas.e...@googlemail.com

unread,
Oct 27, 2015, 5:54:54 AM10/27/15
to javamelody, char...@thelearningbar.com, thomas.e...@googlemail.com
Cheers Emeric, 

I eventually got around the issue by using the new 0.9.5.1 (does not work in previous versions, which caused a lot of frustration) c3p0 property: 

com.mchange.v2.c3p0.management.ExcludeIdentityToken=true
which allowed me to call:


thusly to obtain what I needed. Hope this helps anyone else who runs into this.

Thanks,

Thomas
Reply all
Reply to author
Forward
0 new messages