javaspring-bootmetricshikaricpspring-micrometer

HikariCp metrics collection using micrometer in Java springboot application by configuring it in


community, I have a requirement where I want to do HikariCp metrics collection using micrometre in Java spring boot application by configuring it. I was looking around but I could not find much help in the official documentation

https://github.com/brettwooldridge/HikariCP/tree/dev/src/main/java/com/zaxxer/hikari

Can anyone please help me with how to do that? Note: In the official documentation of Hikari they have provided a way to set metric registry for dropwizard but I wanted to do it with Micrometre.


Solution

  • only data source autoconfigured is exposed for metrics in my case I have a custom Hikari data source configuration.

    public myDataSource(){
       DataSource datasource = this.createDataSource();// you can write your own implementation to create datasource. you can pass URL, username etc to create it.
     this.setUpHikariWithMetrics();
    }
    
    public void setUpHikariWithMetrics() {
        if (dataSource instanceof HikariDataSource) {
            ((HikariDataSource) dataSource).setMetricRegistry(metricRegistry);
        }
    }