diff options
author | Ivan Topolnak <itopolnak@despegar.com> | 2014-02-03 18:10:08 -0300 |
---|---|---|
committer | Ivan Topolnjak <ivantopo@gmail.com> | 2014-02-04 09:18:08 -0300 |
commit | 462c41f32d9e9c3fd84d973a4b3ea4678537987b (patch) | |
tree | 47225d29f634e7a536efc7060d0740d5e7a575d7 /kamon-core/src/main/scala/kamon/metrics | |
parent | 6b44762a034df9f63f6616b11762fb4ebaf92508 (diff) | |
download | Kamon-462c41f32d9e9c3fd84d973a4b3ea4678537987b.tar.gz Kamon-462c41f32d9e9c3fd84d973a4b3ea4678537987b.tar.bz2 Kamon-462c41f32d9e9c3fd84d973a4b3ea4678537987b.zip |
create the notion of a metric group category for easier filtering when subscribing
Diffstat (limited to 'kamon-core/src/main/scala/kamon/metrics')
5 files changed, 55 insertions, 45 deletions
diff --git a/kamon-core/src/main/scala/kamon/metrics/ActorMetrics.scala b/kamon-core/src/main/scala/kamon/metrics/ActorMetrics.scala index a00b443e..4c8752e5 100644 --- a/kamon-core/src/main/scala/kamon/metrics/ActorMetrics.scala +++ b/kamon-core/src/main/scala/kamon/metrics/ActorMetrics.scala @@ -20,9 +20,12 @@ import com.typesafe.config.Config import kamon.metrics.instruments.ContinuousHighDynamicRangeRecorder import org.HdrHistogram.HighDynamicRangeRecorder -object ActorMetrics extends MetricGroupIdentity.Category with MetricGroupFactory { - type GroupRecorder = ActorMetricRecorder - val entityName = "actor" +case class ActorMetrics(name: String) extends MetricGroupIdentity { + val category = ActorMetrics +} + +object ActorMetrics extends MetricGroupCategory { + val name = "actor" case object ProcessingTime extends MetricIdentity { val name, tag = "ProcessingTime" } case object MailboxSize extends MetricIdentity { val name, tag = "MailboxSize" } @@ -51,17 +54,21 @@ object ActorMetrics extends MetricGroupIdentity.Category with MetricGroupFactory (TimeInMailbox -> timeInMailbox)) } - def create(config: Config): ActorMetricRecorder = { - import HighDynamicRangeRecorder.Configuration + val Factory = new MetricGroupFactory { + type GroupRecorder = ActorMetricRecorder - val settings = config.getConfig("kamon.metrics.precision.actor") - val processingTimeHdrConfig = Configuration.fromConfig(settings.getConfig("processing-time")) - val mailboxSizeHdrConfig = Configuration.fromConfig(settings.getConfig("mailbox-size")) - val timeInMailboxHdrConfig = Configuration.fromConfig(settings.getConfig("time-in-mailbox")) + def create(config: Config): ActorMetricRecorder = { + import HighDynamicRangeRecorder.Configuration - new ActorMetricRecorder( - HighDynamicRangeRecorder(processingTimeHdrConfig), - ContinuousHighDynamicRangeRecorder(mailboxSizeHdrConfig), - HighDynamicRangeRecorder(timeInMailboxHdrConfig)) + val settings = config.getConfig("kamon.metrics.precision.actor") + val processingTimeHdrConfig = Configuration.fromConfig(settings.getConfig("processing-time")) + val mailboxSizeHdrConfig = Configuration.fromConfig(settings.getConfig("mailbox-size")) + val timeInMailboxHdrConfig = Configuration.fromConfig(settings.getConfig("time-in-mailbox")) + + new ActorMetricRecorder( + HighDynamicRangeRecorder(processingTimeHdrConfig), + ContinuousHighDynamicRangeRecorder(mailboxSizeHdrConfig), + HighDynamicRangeRecorder(timeInMailboxHdrConfig)) + } } } diff --git a/kamon-core/src/main/scala/kamon/metrics/Metrics.scala b/kamon-core/src/main/scala/kamon/metrics/Metrics.scala index 2a9c5c65..ee32dbe8 100644 --- a/kamon-core/src/main/scala/kamon/metrics/Metrics.scala +++ b/kamon-core/src/main/scala/kamon/metrics/Metrics.scala @@ -20,7 +20,14 @@ import annotation.tailrec import com.typesafe.config.Config import kamon.metrics.MetricSnapshot.Measurement -case class MetricGroupIdentity(name: String, category: MetricGroupIdentity.Category) +trait MetricGroupCategory { + def name: String +} + +trait MetricGroupIdentity { + def name: String + def category: MetricGroupCategory +} trait MetricIdentity { def name: String @@ -96,14 +103,7 @@ object MetricSnapshot { case class DefaultMetricSnapshot(numberOfMeasurements: Long, measurementLevels: Vector[MetricSnapshot.Measurement]) extends MetricSnapshot object MetricGroupIdentity { - trait Category { - def entityName: String - } - val AnyCategory = new Category { - val entityName: String = "match-all" - override def equals(that: Any): Boolean = that.isInstanceOf[Category] - } } trait MetricGroupFactory { diff --git a/kamon-core/src/main/scala/kamon/metrics/MetricsExtension.scala b/kamon-core/src/main/scala/kamon/metrics/MetricsExtension.scala index a717e25a..a8b90b57 100644 --- a/kamon-core/src/main/scala/kamon/metrics/MetricsExtension.scala +++ b/kamon-core/src/main/scala/kamon/metrics/MetricsExtension.scala @@ -22,9 +22,7 @@ import com.typesafe.config.Config import kamon.util.GlobPathFilter import kamon.Kamon import akka.actor -import kamon.metrics.MetricGroupIdentity.Category import kamon.metrics.Metrics.MetricGroupFilter -import scala.Some import kamon.metrics.Subscriptions.Subscribe class MetricsExtension(val system: ExtendedActorSystem) extends Kamon.Extension { @@ -33,18 +31,18 @@ class MetricsExtension(val system: ExtendedActorSystem) extends Kamon.Extension val filters = loadFilters(config) lazy val subscriptions = system.actorOf(Props[Subscriptions], "kamon-metrics-subscriptions") - def register(name: String, category: MetricGroupIdentity.Category with MetricGroupFactory): Option[category.GroupRecorder] = { - if (shouldTrack(name, category)) - Some(storage.getOrElseUpdate(MetricGroupIdentity(name, category), category.create(config)).asInstanceOf[category.GroupRecorder]) + def register(identity: MetricGroupIdentity, factory: MetricGroupFactory): Option[factory.GroupRecorder] = { + if (shouldTrack(identity)) + Some(storage.getOrElseUpdate(identity, factory.create(config)).asInstanceOf[factory.GroupRecorder]) else None } - def unregister(name: String, category: MetricGroupIdentity.Category with MetricGroupFactory): Unit = { - storage.remove(MetricGroupIdentity(name, category)) + def unregister(identity: MetricGroupIdentity): Unit = { + storage.remove(identity) } - def subscribe(category: Category, selection: String, receiver: ActorRef, permanently: Boolean = false): Unit = { + def subscribe[C <: MetricGroupCategory](category: C, selection: String, receiver: ActorRef, permanently: Boolean = false): Unit = { subscriptions.tell(Subscribe(category, selection, permanently), receiver) } @@ -52,8 +50,8 @@ class MetricsExtension(val system: ExtendedActorSystem) extends Kamon.Extension (for ((identity, recorder) ← storage) yield (identity, recorder.collect)).toMap } - private def shouldTrack(name: String, category: MetricGroupIdentity.Category): Boolean = { - filters.get(category.entityName).map(filter ⇒ filter.accept(name)).getOrElse(false) + private def shouldTrack(identity: MetricGroupIdentity): Boolean = { + filters.get(identity.category.name).map(filter ⇒ filter.accept(identity.name)).getOrElse(false) } def loadFilters(config: Config): Map[String, MetricGroupFilter] = { diff --git a/kamon-core/src/main/scala/kamon/metrics/Subscriptions.scala b/kamon-core/src/main/scala/kamon/metrics/Subscriptions.scala index 3151bdc1..654c37b0 100644 --- a/kamon-core/src/main/scala/kamon/metrics/Subscriptions.scala +++ b/kamon-core/src/main/scala/kamon/metrics/Subscriptions.scala @@ -21,7 +21,6 @@ import kamon.metrics.Subscriptions.{ MetricGroupFilter, FlushMetrics, TickMetric import kamon.util.GlobPathFilter import scala.concurrent.duration.Duration import java.util.concurrent.TimeUnit -import kamon.metrics.MetricGroupIdentity.Category import kamon.Kamon class Subscriptions extends Actor { @@ -40,7 +39,7 @@ class Subscriptions extends Actor { case FlushMetrics ⇒ flush() } - def subscribe(category: Category, selection: String, permanent: Boolean): Unit = { + def subscribe(category: MetricGroupCategory, selection: String, permanent: Boolean): Unit = { val filter = MetricGroupFilter(category, new GlobPathFilter(selection)) if (permanent) { val receivers = subscribedPermanently.get(filter).getOrElse(Nil) @@ -78,10 +77,10 @@ class Subscriptions extends Actor { object Subscriptions { case object FlushMetrics - case class Subscribe(category: Category, selection: String, permanently: Boolean = false) + case class Subscribe(category: MetricGroupCategory, selection: String, permanently: Boolean = false) case class TickMetricSnapshot(from: Long, to: Long, metrics: Map[MetricGroupIdentity, MetricGroupSnapshot]) - case class MetricGroupFilter(category: Category, globFilter: GlobPathFilter) { + case class MetricGroupFilter(category: MetricGroupCategory, globFilter: GlobPathFilter) { def accept(identity: MetricGroupIdentity): Boolean = { category.equals(identity.category) && globFilter.accept(identity.name) } diff --git a/kamon-core/src/main/scala/kamon/metrics/TraceMetrics.scala b/kamon-core/src/main/scala/kamon/metrics/TraceMetrics.scala index 66801481..ccffe382 100644 --- a/kamon-core/src/main/scala/kamon/metrics/TraceMetrics.scala +++ b/kamon-core/src/main/scala/kamon/metrics/TraceMetrics.scala @@ -20,12 +20,14 @@ import org.HdrHistogram.HighDynamicRangeRecorder import scala.collection.concurrent.TrieMap import com.typesafe.config.Config -object TraceMetrics extends MetricGroupIdentity.Category with MetricGroupFactory { - type GroupRecorder = TraceMetricRecorder - val entityName = "trace" +case class TraceMetrics(name: String) extends MetricGroupIdentity { + val category = TraceMetrics +} - case object ElapsedTime extends MetricIdentity { val name, tag = "ElapsedTime" } +object TraceMetrics extends MetricGroupCategory { + val name = "trace" + case object ElapsedTime extends MetricIdentity { val name, tag = "ElapsedTime" } case class HttpClientRequest(name: String, tag: String) extends MetricIdentity class TraceMetricRecorder(val elapsedTime: HighDynamicRangeRecorder, private val segmentRecorderFactory: () ⇒ HighDynamicRangeRecorder) @@ -48,14 +50,18 @@ object TraceMetrics extends MetricGroupIdentity.Category with MetricGroupFactory def metrics: Map[MetricIdentity, MetricSnapshot] = segments + (ElapsedTime -> elapsedTime) } - def create(config: Config): TraceMetricRecorder = { - import HighDynamicRangeRecorder.Configuration + val Factory = new MetricGroupFactory { + type GroupRecorder = TraceMetricRecorder - val settings = config.getConfig("kamon.metrics.precision.trace") - val elapsedTimeHdrConfig = Configuration.fromConfig(settings.getConfig("elapsed-time")) - val segmentHdrConfig = Configuration.fromConfig(settings.getConfig("segment")) + def create(config: Config): TraceMetricRecorder = { + import HighDynamicRangeRecorder.Configuration - new TraceMetricRecorder(HighDynamicRangeRecorder(elapsedTimeHdrConfig), () ⇒ HighDynamicRangeRecorder(segmentHdrConfig)) + val settings = config.getConfig("kamon.metrics.precision.trace") + val elapsedTimeHdrConfig = Configuration.fromConfig(settings.getConfig("elapsed-time")) + val segmentHdrConfig = Configuration.fromConfig(settings.getConfig("segment")) + + new TraceMetricRecorder(HighDynamicRangeRecorder(elapsedTimeHdrConfig), () ⇒ HighDynamicRangeRecorder(segmentHdrConfig)) + } } } |