com.sksamuel.cohort.dbcp.DbcpMinIdleHealthCheck.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cohort-dbcp Show documentation
Show all versions of cohort-dbcp Show documentation
Ktor and Vertx Actuator and Monitoring
The newest version!
package com.sksamuel.cohort.dbcp
import com.sksamuel.cohort.HealthCheck
import com.sksamuel.cohort.HealthCheckResult
import org.apache.commons.dbcp2.BasicDataSource
/**
* A Cohort [HealthCheck] that checks for the number of idle connections in a Apache DBCP2 [BasicDataSource].
*
* This is useful to detect when connections are being exhausted.
*
* The check is considered healthy if the idle count is >= [minIdle].
*/
class DbcpMinIdleHealthCheck(
private val ds: BasicDataSource,
private val minIdle: Int,
override val name: String = "dbcp_min_idle",
) : HealthCheck {
override suspend fun check(): HealthCheckResult {
val msg = "Idle connections ${ds.numIdle} [min required is $minIdle]"
return if (ds.numIdle >= minIdle) HealthCheckResult.healthy(msg) else HealthCheckResult.unhealthy(msg, null)
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy