Jbisgood9999999
Jbisgood9999999

Reputation: 253

How to check tomcat datasource connection pool in server.xml

I tried to check the connection pool in server.xml

Here is my server.xml from Tomcat

server.xml

<GlobalNamingResources>
<Resource name="jdbc/test" auth="Container" 
          type="javax.sql.DataSource"
          maxTotal="200" maxIdle="50" maxWaitMillis="10000"
          username="test" password="test" 
          driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
          url="jdbc:sqlserver://localhost\test;databaseName=test"  />
</GlobalNamingResources>

context.xml

<Context>
    <ResourceLink name="jdbc/test"
                 golbal="jdbc/test"
                   type="javax.sql.DataSource" />
</Context>

I have no idea how check the connection pool from server.xml because I put the datasource wrongly / or not in context.xml.

Since the server is in Production Environment and it cannot reset. I cannot change the datasource to context.xml

I check a lots reference and most of the monitor for connection pool is to put the datasource in context.xml

For example : http://www.jcgonzalez.com/java-monitor-jdbc-connection-pool-servlet

I follow all the code above and I can check the connection pool in Testing Environment.

But i cannot check the connection pool from server.xml.

Is there any reference coding to check the datasource connection pool status in server.xml?

I tried

   try {
        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.catalina.mbeans.ContextResourceLinkMBean")) {
                for (MBeanAttributeInfo mf : info.getAttributes()) {
                    Object attributeValue = server.getAttribute(name,
                            mf.getName());
                    if (attributeValue != null) {
                        writer.println("" + mf.getName() + " : "
                                + attributeValue.toString() + "<br/>");

                    }
                }
                break;
            }
        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

But it only return:

name : jdbc/test
global : jdbc/test
type : javax.sql.DataSource

I want to check the connection pool status not the reference in context.xml

Can someone help?

Upvotes: 0

Views: 9256

Answers (1)

Christopher Schultz
Christopher Schultz

Reputation: 20862

This presentation may help you with your monitoring requirements:

Tomcat Presentations - just search for "monitoring".

Upvotes: 1

Related Questions