aboutsummaryrefslogtreecommitdiff
path: root/kamon-core/src/main/scala/kamon/metric
diff options
context:
space:
mode:
authorIvan Topolnak <itopolnak@despegar.com>2014-01-02 18:09:53 -0300
committerIvan Topolnak <itopolnak@despegar.com>2014-01-13 17:37:20 -0300
commit7a10c0ef2a6566229e8571f6d385ca2ff794cc20 (patch)
treececd7ce6eb7a71f967eaa1605615780fa94d346c /kamon-core/src/main/scala/kamon/metric
parent54143e4af6182b967736abc60a7fb20c88dd6587 (diff)
downloadKamon-7a10c0ef2a6566229e8571f6d385ca2ff794cc20.tar.gz
Kamon-7a10c0ef2a6566229e8571f6d385ca2ff794cc20.tar.bz2
Kamon-7a10c0ef2a6566229e8571f6d385ca2ff794cc20.zip
integrate trace and metrics into the base project
Diffstat (limited to 'kamon-core/src/main/scala/kamon/metric')
-rw-r--r--kamon-core/src/main/scala/kamon/metric/ExecutorServiceMetricCollector.scala74
-rw-r--r--kamon-core/src/main/scala/kamon/metric/GaugeGenerator.scala27
-rw-r--r--kamon-core/src/main/scala/kamon/metric/Metrics.scala132
3 files changed, 0 insertions, 233 deletions
diff --git a/kamon-core/src/main/scala/kamon/metric/ExecutorServiceMetricCollector.scala b/kamon-core/src/main/scala/kamon/metric/ExecutorServiceMetricCollector.scala
deleted file mode 100644
index 4c4b93e9..00000000
--- a/kamon-core/src/main/scala/kamon/metric/ExecutorServiceMetricCollector.scala
+++ /dev/null
@@ -1,74 +0,0 @@
-/* ===================================================
- * Copyright © 2013 the kamon project <http://kamon.io/>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ========================================================== */
-package kamon.metric
-
-import java.util.concurrent.{ ThreadPoolExecutor, ExecutorService }
-import scala.concurrent.forkjoin.ForkJoinPool
-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.
- }
-
- def deregister(fullName: String) = {
- Metrics.registry.removeMatching(new MetricFilter {
- def matches(name: String, metric: Metric): Boolean = name.startsWith(fullName)
- })
- }
-}
-
-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))
-
- allMetrics.foreach { case (name, metric) ⇒ Metrics.registry.register(name, metric) }
- }
-}
-
-trait ThreadPoolExecutorMetricCollector {
- import GaugeGenerator._
- import BasicExecutorMetricNames._
-
- def registerThreadPoolExecutor(fullName: String, tpe: ThreadPoolExecutor) = {
- val tpeGauge = newNumericGaugeFor(tpe) _
-
- val allMetrics = Map(
- fullName + queueSize -> tpeGauge(_.getQueue.size()),
- fullName + poolSize -> tpeGauge(_.getPoolSize),
- fullName + activeThreads -> tpeGauge(_.getActiveCount))
-
- 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
deleted file mode 100644
index 9eff2739..00000000
--- a/kamon-core/src/main/scala/kamon/metric/GaugeGenerator.scala
+++ /dev/null
@@ -1,27 +0,0 @@
-/* ===================================================
- * Copyright © 2013 the kamon project <http://kamon.io/>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ========================================================== */
-package kamon.metric
-
-import com.codahale.metrics.Gauge
-
-trait GaugeGenerator {
-
- def newNumericGaugeFor[T, V >: AnyVal](target: T)(generator: T ⇒ V) = new Gauge[V] {
- def getValue: V = generator(target)
- }
-}
-
-object GaugeGenerator extends GaugeGenerator
diff --git a/kamon-core/src/main/scala/kamon/metric/Metrics.scala b/kamon-core/src/main/scala/kamon/metric/Metrics.scala
deleted file mode 100644
index b904ec56..00000000
--- a/kamon-core/src/main/scala/kamon/metric/Metrics.scala
+++ /dev/null
@@ -1,132 +0,0 @@
-/* ===================================================
- * Copyright © 2013 the kamon project <http://kamon.io/>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ========================================================== */
-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 scala.collection.concurrent.TrieMap
-
-object Metrics {
- val registry: MetricRegistry = new MetricRegistry
-
- val consoleReporter = ConsoleReporter.forRegistry(registry).convertDurationsTo(TimeUnit.NANOSECONDS)
- //consoleReporter.build().start(45, TimeUnit.SECONDS)
-
- //val newrelicReporter = NewRelicReporter(registry)
- //newrelicReporter.start(5, TimeUnit.SECONDS)
-
- def include(name: String, metric: Metric) = {
- //registry.register(name, metric)
- }
-
- def exclude(name: String) = {
- registry.removeMatching(new MetricFilter {
- def matches(name: String, metric: Metric): Boolean = name.startsWith(name)
- })
- }
-
- def deregister(fullName: String) = {
- registry.removeMatching(new MetricFilter {
- def matches(name: String, metric: Metric): Boolean = name.startsWith(fullName)
- })
- }
-}
-
-object Watched {
- case object Actor
- case object Dispatcher
-}
-
-object MetricDirectory {
- def nameForDispatcher(actorSystem: String, dispatcher: String) = s"/ActorSystem/${actorSystem}/Dispatcher/${dispatcher}/"
-
- def nameForMailbox(actorSystem: String, actor: String) = s"/ActorSystem/$actorSystem/Actor/$actor/Mailbox"
-
- def nameForActor(actorRef: ActorRef) = actorRef.path.elements.mkString("/")
-
- 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
-}
-
-trait HistogramSnapshot {
- def median: Double
- def max: Double
- def min: Double
-}
-
-case class ActorSystemMetrics(actorSystemName: String) {
- val dispatchers = TrieMap.empty[String, DispatcherMetricCollector]
-
- private[this] def createDispatcherCollector: DispatcherMetricCollector = DispatcherMetricCollector(CodahaleHistogram(), CodahaleHistogram(), CodahaleHistogram())
-
- def registerDispatcher(dispatcherName: String): Option[DispatcherMetricCollector] = {
- val stats = createDispatcherCollector
- dispatchers.put(dispatcherName, stats)
- Some(stats)
- }
-
-}
-
-case class CodahaleHistogram() extends Histogram {
- private[this] val histogram = new com.codahale.metrics.Histogram(new metrics.ExponentiallyDecayingReservoir())
-
- def update(value: Long) = histogram.update(value)
- def snapshot: HistogramSnapshot = {
- val snapshot = histogram.getSnapshot
-
- CodahaleHistogramSnapshot(snapshot.getMedian, snapshot.getMax, snapshot.getMin)
- }
-}
-
-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)
-}
-
-class Atomic[T](val atomic: AtomicReference[T]) {
- @tailrec
- final def update(f: T ⇒ T): T = {
- val oldValue = atomic.get()
- val newValue = f(oldValue)
- if (atomic.compareAndSet(oldValue, newValue)) newValue else update(f)
- }
-
- def get() = atomic.get()
-} \ No newline at end of file