Stackable Actor trait which links Gauge life cycles with the actor life cycle.
When an actor is restarted, gauges can not be created again under the same name in the same metric registry.
By mixing in this trait, all gauges created in this actor will be automatically unregistered before this actor
restarts.
Use it as follows:
object Application {
// The application wide metrics registry.val metricRegistry = new com.codahale.metrics.MetricRegistry()
}
trait Instrumented extends InstrumentedBuilder {
val metricRegistry = Application.metricRegistry
}
class ExampleActor extends Actor with Instrumented with ActorInstrumentedLifecycle {
var counter = 0// The following gauge will automatically unregister before a restart of this actor.
metrics.gauge("sample-gauge"){
counter
}
overridedef receive = {
case 'increment =>
counter += 1
doWork()
}
def doWork(): Unit = {
// etc etc etc
}
}
Stackable Actor trait which links Gauge life cycles with the actor life cycle.
When an actor is restarted, gauges can not be created again under the same name in the same metric registry. By mixing in this trait, all gauges created in this actor will be automatically unregistered before this actor restarts.
Use it as follows: