Converts a code block to a com.codahale.metrics.health.HealthCheck and registers it.
Converts a code block to a com.codahale.metrics.health.HealthCheck and registers it.
Use it as follows:
object Application { // The application wide health check registry. val healthCheckRegistry = new com.codahale.metrics.health.HealthCheckRegistry() } trait Checked extends CheckedBuilder { val healthCheckRegistry = Application.healthCheckRegistry } class Example(db: Database) extends Checked { private[this] val databaseCheck = healthCheck("database") { db.isConnected } }
The code block must have a result of type Boolean
, Try
, Either
, Future
,
com.codahale.metrics.health.HealthCheck.Result, or simply Unit
.
true
indicates healthy, false
indicates unhealthy..toString
) or throwable is used as (un)healthy message.[Any]
or Left[Throwable]
indicates
unhealthy. The embedded value (after applying .toString
) or throwable is used as (un)healthy message.It is also possible to override the health check base name. For example:
class Example(db: Database) extends Checked { override lazy val metricBaseName = MetricName("Overridden.Base.Name") private[this] val databaseCheck = healthCheck("database") { db.isConnected } }
To change the timeout for Future execution, set an implicit duration:
class Example(db: Database) extends Checked { implicit private val timeout = 10.seconds private[this] val databaseCheck = healthCheck("database")(Future { db.isConnected }) }
the name of the health check
the unhealthy message for checkers that return false
, defaults to "Health check failed"
the code block that does the health check
The base name for all metrics created from this builder.
The base name for all metrics created from this builder.
The mixin trait for creating a class which creates health checks.