'HikariCP connection pool Metric information

Hell,

Is there any that I can get the HkariCP connection pool metric information such as total connections, idle connections and so on?

I know HikariPool logs such information like:

Before cleanup pool stats db (total=20, inUse=0, avail=20, waiting=0)

But it is too frequently and my code cannot control it. I would like to log such information in a configurable period such as 1 minutes. BTW, I use Scala Slick 3.0



Solution 1:[1]

HikariCP supports Dropwizard Metrics. Check out this link:

https://github.com/brettwooldridge/HikariCP/wiki/Dropwizard-Metrics

Solution 2:[2]

Dropwizard Metrics: (from https://stackoverflow.com/a/42301023)

    private MetricRegistry metricRegistry;
    ...
    if(dataSource instanceof HikariDataSource) {
        ((HikariDataSource) dataSource).setMetricRegistry(metricRegistry);
    }

Prometheus Metrics:

    private DataSource dataSource;
    ...
    if (dataSource instanceof HikariDataSource) {
        ((HikariDataSource) dataSource).setMetricsTrackerFactory(new PrometheusMetricsTrackerFactory());
    }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 brettw
Solution 2 Mikhail Ionkin