I am trying to figure out how many connections are currently opened and I can't seem to find an obvious way to do that with Hikari.
HikariPool
exposes that information (getActiveConnections
) but I don't see an easy way to access that from HikariDataSource
.
"HikariCP is solid high-performance JDBC connection pool. A connection pool is a cache of database connections maintained so that the connections can be reused when future requests to the database are required. Connection pools may significantly reduce the overall resource usage." - You can find out more here.
Configuring Hikari With Spring Boot 1. x uses the Tomcat JDBC Connection Pool by default. As soon as we include spring-boot-starter-data-jpa into our pom. xml, we'll transitively include a dependency to the Tomcat JDBC implementation. During runtime, Spring Boot will then create a Tomcat DataSource for us to use.
If you are using spring boot:
new HikariDataSourcePoolMetadata(dataSource).getActive();
You'll have to get it via JMX programmatic access. First, enable MBean registration through the registerMbeans
property or by calling setRegisterMeans()
. Then consult this page for how to perform programmatic access:
https://github.com/brettwooldridge/HikariCP/wiki/JMX-Monitoring
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With