Hi Chris,
See below
On 12/5/2019 1:07 PM, Christopher Schultz wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
Jerry,
On 12/5/19 13:42, Jerry Malcolm wrote:
I'm trying to add some code to monitor my jdbc data connection
pool.
Before you do that, is this a pool that is application-managed? If
Tomcat is managing the connection pool, then none of this is
necessary. If it's application-managed, I'm curious as to why you are
doing that rather than having Tomcat manage it for you. Would you mind
explaining if that's the case?
It's tomcat managed.
| >> none of this is necessary
Are you telling me that it's unnecessary for me to know how many
connections are currently in use in my connection pool?? I'm trying to
determine the high-water mark over several days of typical use for how
many concurrent connections are in use in order to not over-allocate.
I'm not 'managing' the connections. I'm simply analyzing the usage of
the pool. I figured the most obvious place to check in-use counts is
each time a new connection is allocated.
Each time a connection is requested, I have some jmx code that
logs values from the datasource mbean.
That sounds wasteful. Why not interrogate the connection pool whenever
a client probes the JMX bean?
No clue what you mean here. There's no situation where the client has
any reason to access a jmx bean. I'm using the jmx bean to collect and
log the current state data for the datasource pool each time a
connection is requested from the pool.
| >> interrogate the connection pool
Is there a way to get the jmx data such as in-use connection count
directly from the jdbc datasource object or some child object? I didn't
see any methods on the datasource to give me that data. That's why I
went to jmx to begin with.
I haven't done much jmx coding. So consider me a rookie on this
topic. I found some code on the web that does pretty much what I
need. The relevant part of the code:
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
Set<ObjectName> objectNames = server.queryNames(null, null); for
(ObjectName name : objectNames) { MBeanInfo info =
server.getMBeanInfo(name); if (info.getClassName().equals(
"org.apache.tomcat.dbcp.pool2.impl.GenericObjectPool")) { for
(MBeanAttributeInfo mf : info.getAttributes()) {
This code works. The problem is that I have a bunch of virtual
hosts running on the same instance of TC. So I get a bunch of
matching mbeans, apparently one for each virtual host / resource
defined.
Is there any way to identify which mbean is for the datasource I
currently care about? I was hoping there would be an attribute
with the datasource name or the database name or even just some way
to add a unique identifier when I create it. But I don't see
anything. I've resorted to having maxTotal set to incrementally
different values in all of my resource statements just so I can
identify the datasource I'm looking at in the logs. But that's a
hack.
Is there a better way to uniquely identify datasource mbeans in
jmx?
Tomcat usually uses the JMX URI (?) space by adding the application's
context-path (and possible hostname) as a part of the path to the
bean. So for you that might be:
com.yourcompany.yourapp/[host]/[app]/datasource
When/how are you binding your bean into the JNDI space?
My code was in my original post. Here it is again. I don't know if
this the best way. As I said, I found this code by googling. It works.
But it just dumps every jdbc datasource mbean for all different
resources without identifying them. I'm not creating and binding my own
mbeans. I'm simply finding beans that already exist.
If there's a way to directly access the bean for a particular datasource
by name, can you show me the alternate code?
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
Set<ObjectName> objectNames = server.queryNames(null, null);
for (ObjectName name : objectNames) {
MBeanInfo info = server.getMBeanInfo(name);
if (info.getClassName().equals(
"org.apache.tomcat.dbcp.pool2.impl.GenericObjectPool")) {
for (MBeanAttributeInfo mf : info.getAttributes()) {
<log the attr name and value>
- -chris
-----BEGIN PGP SIGNATURE-----
Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/
iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAl3pVXQACgkQHPApP6U8
pFiYkhAAj9UqGppFWTsvgiZg30BECln9mppvBCRGUSn/oV5SuGrRgpD+glcCWZEz
ZRcLG1pDF8ze+sS57mU2oMIHO/vPuuBFKM4KmeyXbW1iIKF01PmQxmIG88qjgi2Z
h2/AJKErGIpQ+GhrKSvX27vxrWzb1n7urCkq7PCCml5h20rl4OhaUnSmVGHQkr/6
OlhmL45u2MdLMYAPDasf0bjrA0OPo3jFnn8myjtwVUjo2AGm6SS5RJn7HSB8QxqU
ZNWnWiI40CaBGzJthDoRzKbspd+aCY/qM2dc6dIovL9hCCsEB+J6aJf9oE53+MyV
6md4wWBWVZSFzvkOg8Kjj+mx6QK/j9PC9HZ+nsbWk0kTfutCwZpQZQgtqe8tmAD9
o/xvSUCSRig+PlMK1eYkkU5dYziI/FpWDhURg9zMXiXXnmRr6V2S4zNMK240Zxt1
1ev+QOucv4sjb+Nt8rUc1HazYfcZqfcI/fJjlNjPgPOkjRX3ftbbRIwDBVFwwCFv
lOKt+fQvAZfM8pC7c50BLwl2fpvCRVt8+xHpp3t5EwKSycG55WsD9DmpMoLENNXp
G+UDj+mmkIrPY5zHR+hqB2rMWABk084pWoNlBXlfApwqLcZq6h0fvV6E3IdvqRRD
OhNwz1g2tF4HOgFlfVp0gfzzS9bnaNcgyGpXsrL4s/J8ZTVyfjs=
=QuqP
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org