I am using some code like this to create a pool
(swap! next-jdbc-connection-pools assoc db
(connection/->pool HikariDataSource (make-db-spec-hikari (get-in @config [:databases db]))))
Is there a way I can retrieve the number of active connections in the pool ?
I have seen .getActiveConnections suggested but it does nto seem to be available on (:my-db @next-jdbc-connection-pools)
Evaluation the connection gives me this object #object[com.zaxxer.hikari.HikariDataSource 0x350f54a1 "HikariDataSource (HikariPool-1)"]) so trying to figure out how I pull the info I need from that, any suggestions ?You can get an MX bean from the datasource and then get the counts from that -- here's how we do that at work:
(let [^com.zaxxer.hikari.HikariDataSource ds (:datasource db-spec)]
(if-let [mx-bean (.getHikariPoolMXBean ds)]
(let [total (.getTotalConnections mx-bean)
active (.getActiveConnections mx-bean)
idle (.getIdleConnections mx-bean)]
...thanks for that I will give it a try, I will also go and google MX bean as I have seen that mentioned a few times but not really sure what one is 🙂