diff options
author | Diego Parra <diegolparra@gmail.com> | 2013-11-26 15:54:10 -0300 |
---|---|---|
committer | Diego Parra <diegolparra@gmail.com> | 2013-11-26 15:54:10 -0300 |
commit | 0915ccaf0586e29b0e223c55fdb7acf23fc7264f (patch) | |
tree | 42f4b1feb1ee145789a2a5f83a5a7780bb9126d3 /kamon-core/src | |
parent | ec7c47974a4c06640f67be04e6c1afbbeec36fa7 (diff) | |
download | Kamon-0915ccaf0586e29b0e223c55fdb7acf23fc7264f.tar.gz Kamon-0915ccaf0586e29b0e223c55fdb7acf23fc7264f.tar.bz2 Kamon-0915ccaf0586e29b0e223c55fdb7acf23fc7264f.zip |
added scalariform
Diffstat (limited to 'kamon-core/src')
6 files changed, 34 insertions, 180 deletions
diff --git a/kamon-core/src/main/scala/kamon/AkkaExtensionSwap.scala b/kamon-core/src/main/scala/kamon/AkkaExtensionSwap.scala index 153f9335..c0994f2c 100644 --- a/kamon-core/src/main/scala/kamon/AkkaExtensionSwap.scala +++ b/kamon-core/src/main/scala/kamon/AkkaExtensionSwap.scala @@ -15,7 +15,7 @@ * ========================================================== */ package kamon -import akka.actor.{Extension, ActorSystem, ExtensionId} +import akka.actor.{ Extension, ActorSystem, ExtensionId } import java.util.concurrent.ConcurrentHashMap object AkkaExtensionSwap { diff --git a/kamon-core/src/main/scala/kamon/instrumentation/ExecutorServiceMetrics.scala b/kamon-core/src/main/scala/kamon/instrumentation/ExecutorServiceMetrics.scala index 995b8e7f..a3da76f7 100644 --- a/kamon-core/src/main/scala/kamon/instrumentation/ExecutorServiceMetrics.scala +++ b/kamon-core/src/main/scala/kamon/instrumentation/ExecutorServiceMetrics.scala @@ -19,14 +19,13 @@ import org.aspectj.lang.annotation._ import java.util.concurrent._ import org.aspectj.lang.ProceedingJoinPoint import java.util -import kamon.metric.{DispatcherMetricCollector, Histogram, MetricDirectory, ExecutorServiceMetricCollector} -import akka.dispatch.{MonitorableThreadFactory, ExecutorServiceFactory} +import kamon.metric.{ DispatcherMetricCollector, Histogram, MetricDirectory, ExecutorServiceMetricCollector } +import akka.dispatch.{ MonitorableThreadFactory, ExecutorServiceFactory } import com.typesafe.config.Config import kamon.Kamon import scala.concurrent.forkjoin.ForkJoinPool import akka.dispatch.ForkJoinExecutorConfigurator.AkkaForkJoinPool - @Aspect class ActorSystemInstrumentation { @@ -64,12 +63,9 @@ class ForkJoinPoolInstrumentation { } def splitName(threadFactoryName: String, knownActorSystems: List[String]): (String, String) = { - knownActorSystems.find(threadFactoryName.startsWith(_)).map(asName => (asName, threadFactoryName.substring(asName.length+1))).getOrElse(("Unkown", "Unkown")) + knownActorSystems.find(threadFactoryName.startsWith(_)).map(asName ⇒ (asName, threadFactoryName.substring(asName.length + 1))).getOrElse(("Unkown", "Unkown")) } - - - @Pointcut("execution(* scala.concurrent.forkjoin.ForkJoinPool.scan(..)) && this(fjp)") def forkJoinScan(fjp: AkkaForkJoinPool): Unit = {} @@ -79,39 +75,8 @@ class ForkJoinPoolInstrumentation { poolSizeHistogram.update(fjp.getPoolSize) } - - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /** * ExecutorService monitoring base: */ @@ -125,19 +90,6 @@ trait WatchedExecutorService { def collector: ExecutorServiceCollector } - - - - - - - - - - - - - trait ExecutorServiceMonitoring { def dispatcherMetrics: DispatcherMetricCollector } @@ -146,21 +98,6 @@ class ExecutorServiceMonitoringImpl extends ExecutorServiceMonitoring { @volatile var dispatcherMetrics: DispatcherMetricCollector = _ } - - - - - - - - - - - - - - - case class NamedExecutorServiceFactoryDelegate(actorSystemName: String, dispatcherName: String, delegate: ExecutorServiceFactory) extends ExecutorServiceFactory { def createExecutorService: ExecutorService = delegate.createExecutorService } @@ -178,8 +115,8 @@ class ExecutorServiceFactoryProviderInstrumentation { val delegate = pjp.proceed().asInstanceOf[ExecutorServiceFactory] // Safe Cast val actorSystemName = threadFactory match { - case m: MonitorableThreadFactory => m.name - case _ => "Unknown" // Find an alternative way to find the actor system name in case we start seeing "Unknown" as the AS name. + case m: MonitorableThreadFactory ⇒ m.name + case _ ⇒ "Unknown" // Find an alternative way to find the actor system name in case we start seeing "Unknown" as the AS name. } new NamedExecutorServiceFactoryDelegate(actorSystemName, dispatcherName, delegate) @@ -187,7 +124,6 @@ class ExecutorServiceFactoryProviderInstrumentation { } - @Aspect class NamedExecutorServiceFactoryDelegateInstrumentation { @@ -224,37 +160,3 @@ case class NamedExecutorServiceDelegate(fullName: String, delegate: ExecutorServ def execute(command: Runnable) = delegate.execute(command) } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/kamon-core/src/main/scala/kamon/instrumentation/MessageQueueMetrics.scala b/kamon-core/src/main/scala/kamon/instrumentation/MessageQueueMetrics.scala index 65539beb..da797fa1 100644 --- a/kamon-core/src/main/scala/kamon/instrumentation/MessageQueueMetrics.scala +++ b/kamon-core/src/main/scala/kamon/instrumentation/MessageQueueMetrics.scala @@ -15,20 +15,18 @@ * ========================================================== */ package kamon.instrumentation -import com.codahale.metrics.{ExponentiallyDecayingReservoir, Histogram} -import akka.dispatch.{UnboundedMessageQueueSemantics, Envelope, MessageQueue} -import org.aspectj.lang.annotation.{Around, Pointcut, DeclareMixin, Aspect} -import akka.actor.{ActorSystem, ActorRef} -import kamon.metric.{Metrics, MetricDirectory} +import com.codahale.metrics.{ ExponentiallyDecayingReservoir, Histogram } +import akka.dispatch.{ UnboundedMessageQueueSemantics, Envelope, MessageQueue } +import org.aspectj.lang.annotation.{ Around, Pointcut, DeclareMixin, Aspect } +import akka.actor.{ ActorSystem, ActorRef } +import kamon.metric.{ Metrics, MetricDirectory } import org.aspectj.lang.ProceedingJoinPoint - /** * For Mailboxes we would like to track the queue size and message latency. Currently the latency * will be gathered from the ActorCellMetrics. */ - @Aspect class MessageQueueInstrumentation { @@ -40,7 +38,7 @@ class MessageQueueInstrumentation { val delegate = pjp.proceed.asInstanceOf[MessageQueue] // We are not interested in monitoring mailboxes if we don't know where they belong to. - val monitoredMailbox = for(own <- owner; sys <- system) yield { + val monitoredMailbox = for (own ← owner; sys ← system) yield { val systemName = sys.name val ownerName = MetricDirectory.nameForActor(own) val mailBoxName = MetricDirectory.nameForMailbox(systemName, ownerName) @@ -52,14 +50,13 @@ class MessageQueueInstrumentation { } monitoredMailbox match { - case None => delegate - case Some(mmb) => mmb + case None ⇒ delegate + case Some(mmb) ⇒ mmb } } } - -class MonitoredMessageQueue(val delegate: MessageQueue, val queueSizeHistogram: Histogram) extends MessageQueue with UnboundedMessageQueueSemantics{ +class MonitoredMessageQueue(val delegate: MessageQueue, val queueSizeHistogram: Histogram) extends MessageQueue with UnboundedMessageQueueSemantics { def enqueue(receiver: ActorRef, handle: Envelope) = { delegate.enqueue(receiver, handle) @@ -78,11 +75,3 @@ class MonitoredMessageQueue(val delegate: MessageQueue, val queueSizeHistogram: def cleanUp(owner: ActorRef, deadLetters: MessageQueue) = delegate.cleanUp(owner, deadLetters) } - - - - - - - - diff --git a/kamon-core/src/main/scala/kamon/metric/ExecutorServiceMetricCollector.scala b/kamon-core/src/main/scala/kamon/metric/ExecutorServiceMetricCollector.scala index a99deb5b..4c4b93e9 100644 --- a/kamon-core/src/main/scala/kamon/metric/ExecutorServiceMetricCollector.scala +++ b/kamon-core/src/main/scala/kamon/metric/ExecutorServiceMetricCollector.scala @@ -15,16 +15,16 @@ * ========================================================== */ package kamon.metric -import java.util.concurrent.{ThreadPoolExecutor, ExecutorService} +import java.util.concurrent.{ ThreadPoolExecutor, ExecutorService } import scala.concurrent.forkjoin.ForkJoinPool -import com.codahale.metrics.{Metric, MetricFilter} +import com.codahale.metrics.{ Metric, MetricFilter } object ExecutorServiceMetricCollector extends ForkJoinPoolMetricCollector with ThreadPoolExecutorMetricCollector { def register(fullName: String, executorService: ExecutorService) = executorService match { - case fjp: ForkJoinPool => registerForkJoinPool(fullName, fjp) - case tpe: ThreadPoolExecutor => registerThreadPoolExecutor(fullName, tpe) - case _ => // If it is a unknown Executor then just do nothing. + case fjp: ForkJoinPool ⇒ registerForkJoinPool(fullName, fjp) + case tpe: ThreadPoolExecutor ⇒ registerThreadPoolExecutor(fullName, tpe) + case _ ⇒ // If it is a unknown Executor then just do nothing. } def deregister(fullName: String) = { @@ -34,22 +34,19 @@ object ExecutorServiceMetricCollector extends ForkJoinPoolMetricCollector with T } } - trait ForkJoinPoolMetricCollector { import GaugeGenerator._ import BasicExecutorMetricNames._ - def registerForkJoinPool(fullName: String, fjp: ForkJoinPool) = { val forkJoinPoolGauge = newNumericGaugeFor(fjp) _ val allMetrics = Map( - fullName + queueSize -> forkJoinPoolGauge(_.getQueuedTaskCount.toInt), - fullName + poolSize -> forkJoinPoolGauge(_.getPoolSize), - fullName + activeThreads -> forkJoinPoolGauge(_.getActiveThreadCount) - ) + fullName + queueSize -> forkJoinPoolGauge(_.getQueuedTaskCount.toInt), + fullName + poolSize -> forkJoinPoolGauge(_.getPoolSize), + fullName + activeThreads -> forkJoinPoolGauge(_.getActiveThreadCount)) - allMetrics.foreach { case (name, metric) => Metrics.registry.register(name, metric) } + allMetrics.foreach { case (name, metric) ⇒ Metrics.registry.register(name, metric) } } } @@ -61,22 +58,17 @@ trait ThreadPoolExecutorMetricCollector { val tpeGauge = newNumericGaugeFor(tpe) _ val allMetrics = Map( - fullName + queueSize -> tpeGauge(_.getQueue.size()), - fullName + poolSize -> tpeGauge(_.getPoolSize), - fullName + activeThreads -> tpeGauge(_.getActiveCount) - ) + fullName + queueSize -> tpeGauge(_.getQueue.size()), + fullName + poolSize -> tpeGauge(_.getPoolSize), + fullName + activeThreads -> tpeGauge(_.getActiveCount)) - allMetrics.foreach { case (name, metric) => Metrics.registry.register(name, metric) } + allMetrics.foreach { case (name, metric) ⇒ Metrics.registry.register(name, metric) } } } - object BasicExecutorMetricNames { val queueSize = "queueSize" val poolSize = "threads/poolSize" val activeThreads = "threads/activeThreads" } - - - diff --git a/kamon-core/src/main/scala/kamon/metric/GaugeGenerator.scala b/kamon-core/src/main/scala/kamon/metric/GaugeGenerator.scala index 1d50974d..9eff2739 100644 --- a/kamon-core/src/main/scala/kamon/metric/GaugeGenerator.scala +++ b/kamon-core/src/main/scala/kamon/metric/GaugeGenerator.scala @@ -19,7 +19,7 @@ import com.codahale.metrics.Gauge trait GaugeGenerator { - def newNumericGaugeFor[T, V >: AnyVal](target: T)(generator: T => V) = new Gauge[V] { + def newNumericGaugeFor[T, V >: AnyVal](target: T)(generator: T ⇒ V) = new Gauge[V] { def getValue: V = generator(target) } } diff --git a/kamon-core/src/main/scala/kamon/metric/Metrics.scala b/kamon-core/src/main/scala/kamon/metric/Metrics.scala index dcd54bc7..b904ec56 100644 --- a/kamon-core/src/main/scala/kamon/metric/Metrics.scala +++ b/kamon-core/src/main/scala/kamon/metric/Metrics.scala @@ -18,10 +18,9 @@ package kamon.metric import java.util.concurrent.TimeUnit import akka.actor.ActorRef import com.codahale.metrics -import com.codahale.metrics.{MetricFilter, Metric, ConsoleReporter, MetricRegistry} +import com.codahale.metrics.{ MetricFilter, Metric, ConsoleReporter, MetricRegistry } import scala.collection.concurrent.TrieMap - object Metrics { val registry: MetricRegistry = new MetricRegistry @@ -41,8 +40,6 @@ object Metrics { }) } - - def deregister(fullName: String) = { registry.removeMatching(new MetricFilter { def matches(name: String, metric: Metric): Boolean = name.startsWith(fullName) @@ -64,30 +61,14 @@ object MetricDirectory { def shouldInstrument(actorSystem: String): Boolean = !actorSystem.startsWith("kamon") - def shouldInstrumentActor(actorPath: String): Boolean = { !(actorPath.isEmpty || actorPath.startsWith("system")) } - } - - - - - - - - - - - case class DispatcherMetricCollector(activeThreadCount: Histogram, poolSize: Histogram, queueSize: Histogram) - - - trait Histogram { def update(value: Long): Unit def snapshot: HistogramSnapshot @@ -99,7 +80,6 @@ trait HistogramSnapshot { def min: Double } - case class ActorSystemMetrics(actorSystemName: String) { val dispatchers = TrieMap.empty[String, DispatcherMetricCollector] @@ -113,7 +93,6 @@ case class ActorSystemMetrics(actorSystemName: String) { } - case class CodahaleHistogram() extends Histogram { private[this] val histogram = new com.codahale.metrics.Histogram(new metrics.ExponentiallyDecayingReservoir()) @@ -127,31 +106,23 @@ case class CodahaleHistogram() extends Histogram { case class CodahaleHistogramSnapshot(median: Double, max: Double, min: Double) extends HistogramSnapshot - - - - - - /** * Dispatcher Metrics that we care about currently with a histogram-like nature: * - Work Queue Size * - Total/Active Thread Count */ - - import annotation.tailrec import java.util.concurrent.atomic.AtomicReference object Atomic { - def apply[T]( obj : T) = new Atomic(new AtomicReference(obj)) - implicit def toAtomic[T]( ref : AtomicReference[T]) : Atomic[T] = new Atomic(ref) + def apply[T](obj: T) = new Atomic(new AtomicReference(obj)) + implicit def toAtomic[T](ref: AtomicReference[T]): Atomic[T] = new Atomic(ref) } -class Atomic[T](val atomic : AtomicReference[T]) { +class Atomic[T](val atomic: AtomicReference[T]) { @tailrec - final def update(f: T => T) : T = { + final def update(f: T ⇒ T): T = { val oldValue = atomic.get() val newValue = f(oldValue) if (atomic.compareAndSet(oldValue, newValue)) newValue else update(f) |