views:

255

answers:

1

I am trying to find a setting by which the connection pool monitoring information would come in the server.log whenever an error like "error allocating a connection" or "connection closed" occur.

I found some blog entries that talk about this but they mention it from GUI prespective. However, I want a setting on the connection pool itself so that perodically the connection pool monitoring information would be shown in the logs.

Does anyone know of such a setting?

On Sun app Server 8.X it used to be perf-monitor

+1  A: 

I don't know if this might help you .... but you can interrogate the connection pool monitoring information via jmx. This code code will print the max-pool-size and number of used connections for all connection pools in the appserver (there are loads more stuff you can pull from the MBeans) :

    MBeanServerConnection conn = getMbeanServerConnection();

    //search the jmx register for the specified beans
    Set<ObjectInstance> connectorPoolSet =  conn.queryMBeans(new ObjectName("*:type=jdbc-connection-pool,*"), null);
    Map<String , ObjectName> configMap = new HashMap<String, ObjectName>();
    Map<String , ObjectName> monitorMap = new HashMap<String, ObjectName>();

    //get a map of each config & monitor object found for the search
    for(ObjectInstance oi : connectorPoolSet) {
        String name = oi.getObjectName().getKeyProperty("name");

        //if the category of the mbean is config - put it in the config map - else if it is monitor
        //place it in the monitor map.
        String category = oi.getObjectName().getKeyProperty("category");
        if("config".equalsIgnoreCase(category)) {
            configMap.put(name, oi.getObjectName());
        } else if("monitor".equalsIgnoreCase(category)){
            monitorMap.put(name, oi.getObjectName());
        }
    }

    //iterate the pairs of config & monitor mbeans found 
    for(String name : configMap.keySet()) {

        ObjectName configObjectName  = configMap.get(name);
        ObjectName monitorObjectName = monitorMap.get(name);
        if(monitorObjectName == null) {
            //no monitor found - throw an exception or something
        }

        int maxPoolSizeVal = getAttributeValue(conn, configObjectName, "max-pool-size");
        int connectionsInUse = getAttributeValue(conn, monitorObjectName, "numconnused-current");

        System.out.println(name + " -> max-pool-size : " + maxPoolSizeVal);
        System.out.println(name + " -> connections in use : " + connectionsInUse);


    }
ChristiaanP