diff options
author | Ivan Topolnjak <ivantopo@gmail.com> | 2016-03-15 23:31:11 +0100 |
---|---|---|
committer | Ivan Topolnjak <ivantopo@gmail.com> | 2016-03-15 23:31:11 +0100 |
commit | 60880bb1b6ec15f40ecacf5ab46c849a86ce4b60 (patch) | |
tree | 0fe880c75b891b99f3503d876b3f7e98de11a67b /kamon-akka/src/main/scala/kamon/akka/instrumentation/RouterMonitor.scala | |
parent | cf45b7bcac148945ff209fd7abefc761d916be9a (diff) | |
parent | 9e52aad6b02da72ca28d52d0c94e2e8784e7aa65 (diff) | |
download | Kamon-60880bb1b6ec15f40ecacf5ab46c849a86ce4b60.tar.gz Kamon-60880bb1b6ec15f40ecacf5ab46c849a86ce4b60.tar.bz2 Kamon-60880bb1b6ec15f40ecacf5ab46c849a86ce4b60.zip |
Merge branch 'issue#271/fix-balancing-pool-metrics'
Diffstat (limited to 'kamon-akka/src/main/scala/kamon/akka/instrumentation/RouterMonitor.scala')
-rw-r--r-- | kamon-akka/src/main/scala/kamon/akka/instrumentation/RouterMonitor.scala | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/kamon-akka/src/main/scala/kamon/akka/instrumentation/RouterMonitor.scala b/kamon-akka/src/main/scala/kamon/akka/instrumentation/RouterMonitor.scala new file mode 100644 index 00000000..5c4c7aa3 --- /dev/null +++ b/kamon-akka/src/main/scala/kamon/akka/instrumentation/RouterMonitor.scala @@ -0,0 +1,61 @@ +package akka.kamon.instrumentation + +import akka.actor.{ Cell, Props, ActorRef, ActorSystem } +import akka.dispatch.{ Envelope, MessageDispatcher } +import akka.routing.RoutedActorCell +import kamon.Kamon +import kamon.akka.RouterMetrics +import kamon.metric.Entity +import kamon.util.RelativeNanoTimestamp +import org.aspectj.lang.ProceedingJoinPoint +import org.aspectj.lang.annotation._ + +trait RouterMonitor { + def processMessage(pjp: ProceedingJoinPoint): AnyRef + def processFailure(failure: Throwable): Unit + def cleanup(): Unit + + def routeeAdded(): Unit + def routeeRemoved(): Unit +} + +object RouterMonitor { + + def createRouterInstrumentation(cell: Cell): RouterMonitor = { + val cellInfo = CellInfo.cellInfoFor(cell, cell.system, cell.self, cell.parent) + def routerMetrics = Kamon.metrics.entity(RouterMetrics, cellInfo.entity) + + if (cellInfo.isTracked) + new MetricsOnlyRouterMonitor(cellInfo.entity, routerMetrics) + else NoOpRouterMonitor + } +} + +object NoOpRouterMonitor extends RouterMonitor { + def processMessage(pjp: ProceedingJoinPoint): AnyRef = pjp.proceed() + def processFailure(failure: Throwable): Unit = {} + def routeeAdded(): Unit = {} + def routeeRemoved(): Unit = {} + def cleanup(): Unit = {} +} + +class MetricsOnlyRouterMonitor(entity: Entity, routerMetrics: RouterMetrics) extends RouterMonitor { + + def processMessage(pjp: ProceedingJoinPoint): AnyRef = { + val timestampBeforeProcessing = RelativeNanoTimestamp.now + + try { + pjp.proceed() + } finally { + val timestampAfterProcessing = RelativeNanoTimestamp.now + val routingTime = timestampAfterProcessing - timestampBeforeProcessing + + routerMetrics.routingTime.record(routingTime.nanos) + } + } + + def processFailure(failure: Throwable): Unit = {} + def routeeAdded(): Unit = {} + def routeeRemoved(): Unit = {} + def cleanup(): Unit = Kamon.metrics.removeEntity(entity) +}
\ No newline at end of file |