cannot get the MaxConnections of HikariCP by MBeanServer (JMX)

77 Views Asked by At

I can get "ActiveConnections","IdleConnections","ThreadsAwaitingConnection","TotalConnections" of HikariPool;
but throws error of "No such Attribute Max Connections" when I obtain "MaxConnections".

ERROR message

The property define This the property define in "is in com.zaxxer.hikari.metrics.dropwizard.CodaHaleMetricsTracker.class"

This is my code :

@RestController
public class HikariController {

    private final static Logger LOGGER = LoggerFactory.getLogger(HikariController.class);

    final private MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();

    @RequestMapping("/getMonitor")
    public void getMonitor(){
         hikariCPMap();
    }
    private void hikariCPMap() {

        Hashtable<String, String> table = new Hashtable();
        table.put("type", "Pool (ds1)");
        ObjectName objectName = null;
        try {
            objectName = new ObjectName("com.zaxxer.hikari", table);
        } catch (MalformedObjectNameException e) {
            LOGGER.info(e.toString());
        }
        Set<ObjectName> objectNameSet = mBeanServer.queryNames(objectName, null);
        StringBuilder sb = new StringBuilder();
        for (ObjectName objectName1 : objectNameSet) {
            try {
                LOGGER.info("Active : {}",mBeanServer.getAttribute(objectName, "ActiveConnections").toString());
                LOGGER.info("Idle : {}",mBeanServer.getAttribute(objectName, "IdleConnections").toString());
                LOGGER.info("Waiting : {}",mBeanServer.getAttribute(objectName, "ThreadsAwaitingConnection").toString());
                LOGGER.info("Total : {}",mBeanServer.getAttribute(objectName, "TotalConnections").toString());
                LOGGER.info("Max{} : ",mBeanServer.getAttribute(objectName, "MaxConnections").toString());
            } catch (Exception e) {
                System.out.println(e);
            }
        }
    }
}

How can if fix it ;
I use Hikaricp Version is 3.2.0

1

There are 1 best solutions below

2
SerhiiH On

It happening because there is no property called maxConnections in HikariPool bean. Try using MaximumPoolSize property of HikariConfig instead if that is necessary.

Check those references: HikariPoolMXBean.java, HikariConfigMXBean.java