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

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

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

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

Reply via email to