aboutsummaryrefslogtreecommitdiff
path: root/kamon-core/src/main/scala/kamon/metric
diff options
context:
space:
mode:
authorDiego Parra <diegolparra@gmail.com>2013-11-26 15:54:10 -0300
committerDiego Parra <diegolparra@gmail.com>2013-11-26 15:54:10 -0300
commit5e0b032bfef9509e64af2960452aed44b6e6cb22 (patch)
tree464573c5093b966eaddc65b52244bb1b50c03857 /kamon-core/src/main/scala/kamon/metric
parentdad8547a63d65a5b929346310d53ba2ab45d615c (diff)
downloadKamon-5e0b032bfef9509e64af2960452aed44b6e6cb22.tar.gz
Kamon-5e0b032bfef9509e64af2960452aed44b6e6cb22.tar.bz2
Kamon-5e0b032bfef9509e64af2960452aed44b6e6cb22.zip
added scalariform
Diffstat (limited to 'kamon-core/src/main/scala/kamon/metric')
-rw-r--r--kamon-core/src/main/scala/kamon/metric/ExecutorServiceMetricCollector.scala34
-rw-r--r--kamon-core/src/main/scala/kamon/metric/GaugeGenerator.scala2
-rw-r--r--kamon-core/src/main/scala/kamon/metric/Metrics.scala39
3 files changed, 19 insertions, 56 deletions
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)