繁体   English   中英

JDBC连接池监视GlassFish

[英]JDBC Connection pool monitoring GlassFish

我试图找到一个设置,每当出现“错误分配连接”或“连接关闭”等错误时,连接池监视信息将通过该设置进入server.log。

我发现一些博客条目谈论这个,但他们从GUI提出它。 但是,我想在连接池本身上进行设置,以便在日志中显示连接池监视信息。

有谁知道这样的设置?

在Sun app Server 8.X上,它曾经是perf-monitor

我不知道这是否可以帮助你......但你可以通过jmx查询连接池监控信息。 此代码将打印appserver中所有连接池的max-pool-size和已使用连接数(可以从MBean中加载更多内容):

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


    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM