hy0521
hy0521

Reputation: 73

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

Upvotes: 2

Views: 26121

Answers (2)

Mikhail Ionkin
Mikhail Ionkin

Reputation: 625

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());
    }

Upvotes: 0

brettw
brettw

Reputation: 11114

HikariCP supports Dropwizard Metrics. Check out this link:

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

Upvotes: 10

Related Questions