trait CheckedBuilder extends BaseBuilder
The mixin trait for creating a class which creates health checks.
Linear Supertypes
Known Subclasses
Ordering
- Alphabetic
- By Inheritance
Inherited
- CheckedBuilder
- BaseBuilder
- AnyRef
- Any
- Hide All
- Show All
Visibility
- Public
- All
Abstract Value Members
-
abstract
def
registry: HealthCheckRegistry
The com.codahale.metrics.health.HealthCheckRegistry where created metrics are registered.
Concrete Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
healthCheck[T](name: String, unhealthyMessage: String = "Health check failed")(checker: ⇒ T)(implicit toMagnet: (ByName[T]) ⇒ HealthCheckMagnet): HealthCheck
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 registry = Application.healthCheckRegistry } class ExampleWorker extends Checked { healthCheck("alive") { workerThreadIsActive() } }
The code block must have a result of type
Boolean
,Try
,Either
,Future
, com.codahale.metrics.health.HealthCheck.Result, or simplyUnit
.- A check result of
true
indicates healthy,false
indicates unhealthy. - A check result of type Success indicates healthy, Failure indicates
unhealthy. The embedded value (after applying
.toString
) or throwable is used as (un)healthy message. - A check result of type Future will have 3 seconds to execute (by default). The result of the execution will be treated as Success or Failure.
- A check result of type Right indicates healthy, Left
[Any]
or Left[Throwable]
indicates unhealthy. The embedded value (after applying.toString
) or throwable is used as (un)healthy message. - If the check result is of type com.codahale.metrics.health.HealthCheck.Result, the result is passed unchanged.
- A check result of type Unit indicates healthy.
- If a checker throws an exception, the result is considered unhealthy with the throwable as unhealthy message.
It is also possible to override the health check base name. For example:
class ExampleWorker extends Checked { override lazy val metricBaseName = MetricName("Overridden.Base.Name") healthCheck("alive") { workerThreadIsActive() } }
To change the timeout for Future execution, set an implicit duration:
class ExampleWorker extends Checked { implicit private val timeout = 10.seconds healthCheck("alive")(Future { workerThreadIsActive() }) } NOTE: only one health check can be registered under a name (including the base name which is derived from the class name by default). Any subsequent health check registrations will be ignored. This happens for example when a class that defines a health check is instantiated multiple times. This metrics-core behavior might be changed with https://github.com/dropwizard/metrics/issues/1245. @param name the name of the health check @param unhealthyMessage the unhealthy message for checkers that return `false`, defaults to `"Health check failed"` @param checker the code block that does the health check
- A check result of
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
lazy val
metricBaseName: MetricName
The base name for all metrics created from this builder.
The base name for all metrics created from this builder.
- Definition Classes
- BaseBuilder
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()