From 3566482d061248ff01882fa9647ae2d65677d5ed Mon Sep 17 00:00:00 2001 From: Ivan Topolnjak Date: Mon, 14 Mar 2016 21:59:02 +0100 Subject: introduce selective instrumentation for akka actors. --- .../kamon/akka/instrumentation/CellInfo.scala | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 kamon-akka/src/main/scala/kamon/akka/instrumentation/CellInfo.scala (limited to 'kamon-akka/src/main/scala/kamon/akka/instrumentation/CellInfo.scala') diff --git a/kamon-akka/src/main/scala/kamon/akka/instrumentation/CellInfo.scala b/kamon-akka/src/main/scala/kamon/akka/instrumentation/CellInfo.scala new file mode 100644 index 00000000..e144e605 --- /dev/null +++ b/kamon-akka/src/main/scala/kamon/akka/instrumentation/CellInfo.scala @@ -0,0 +1,31 @@ +package akka.kamon.instrumentation + +import akka.actor.{ Cell, ActorRef, ActorSystem } +import akka.routing.{ RoutedActorRef, RoutedActorCell } +import kamon.Kamon +import kamon.akka.{ ActorMetrics, RouterMetrics } +import kamon.metric.Entity + +case class CellInfo(entity: Entity, isRouter: Boolean, isRoutee: Boolean, isTracked: Boolean) + +object CellInfo { + + def cellName(system: ActorSystem, ref: ActorRef): String = + system.name + "/" + ref.path.elements.mkString("/") + + def cellInfoFor(cell: Cell, system: ActorSystem, ref: ActorRef, parent: ActorRef): CellInfo = { + import kamon.metric.Entity + + val pathString = ref.path.elements.mkString("/") + val isRootSupervisor = pathString.length == 0 || pathString == "user" || pathString == "system" + val isRouter = cell.isInstanceOf[RoutedActorCell] + val isRoutee = parent.isInstanceOf[RoutedActorRef] + + val name = if (isRoutee) cellName(system, parent) else cellName(system, ref) + val category = if (isRouter || isRoutee) RouterMetrics.category else ActorMetrics.category + val entity = Entity(name, category) + val isTracked = !isRootSupervisor && Kamon.metrics.shouldTrack(entity) + + CellInfo(entity, isRouter, isRoutee, isTracked) + } +} \ No newline at end of file -- cgit v1.2.3