sql

oly 2023-08-02T09:07:21.902199Z

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 ?

seancorfield 2023-08-02T16:48:53.204479Z

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)]
...

oly 2023-08-07T08:22:51.918999Z

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 🙂