diff options
Diffstat (limited to 'kamon-akka/src/main/scala/kamon/akka/instrumentation/CellInfo.scala')
-rw-r--r-- | kamon-akka/src/main/scala/kamon/akka/instrumentation/CellInfo.scala | 31 |
1 files changed, 31 insertions, 0 deletions
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 |