diff options
author | Ivan Topolnak <itopolnak@despegar.com> | 2014-01-30 18:23:33 -0300 |
---|---|---|
committer | Ivan Topolnak <itopolnak@despegar.com> | 2014-01-30 18:23:33 -0300 |
commit | a0a57b110a3ee4876797ab51c4758525d166796f (patch) | |
tree | 6da0606b82ace548ed1a76f9d2cfac309723ba1e /kamon-core/src/main/scala/kamon/metrics | |
parent | 8cb7b204bfd77cef8535b467798d88b1aa0c6d24 (diff) | |
download | Kamon-a0a57b110a3ee4876797ab51c4758525d166796f.tar.gz Kamon-a0a57b110a3ee4876797ab51c4758525d166796f.tar.bz2 Kamon-a0a57b110a3ee4876797ab51c4758525d166796f.zip |
wip
Diffstat (limited to 'kamon-core/src/main/scala/kamon/metrics')
4 files changed, 76 insertions, 11 deletions
diff --git a/kamon-core/src/main/scala/kamon/metrics/ActorMetrics.scala b/kamon-core/src/main/scala/kamon/metrics/ActorMetrics.scala index 96d2cd48..e588449e 100644 --- a/kamon-core/src/main/scala/kamon/metrics/ActorMetrics.scala +++ b/kamon-core/src/main/scala/kamon/metrics/ActorMetrics.scala @@ -20,8 +20,8 @@ import com.typesafe.config.Config import org.HdrHistogram.HighDynamicRangeRecorder object ActorMetrics extends MetricGroupIdentity.Category with MetricGroupFactory { - val name: String = "actor" - type Group = ActorMetricRecorder + type GroupRecorder = ActorMetricRecorder + val entityName = "actor" case object ProcessingTime extends MetricIdentity { val name = "ProcessingTime" } case object MailboxSize extends MetricIdentity { val name = "MailboxSize" } @@ -53,12 +53,12 @@ object ActorMetrics extends MetricGroupIdentity.Category with MetricGroupFactory def create(config: Config): ActorMetricRecorder = { import HighDynamicRangeRecorder.Configuration - val settings = config.getConfig("kamon.metrics.actors.hdr-settings") + 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")) - ActorMetricRecorder( + new ActorMetricRecorder( HighDynamicRangeRecorder(processingTimeHdrConfig), HighDynamicRangeRecorder(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 61f79a29..a3d7af87 100644 --- a/kamon-core/src/main/scala/kamon/metrics/Metrics.scala +++ b/kamon-core/src/main/scala/kamon/metrics/Metrics.scala @@ -96,17 +96,17 @@ case class DefaultMetricSnapshot(numberOfMeasurements: Long, measurementLevels: object MetricGroupIdentity { trait Category { - def name: String + def entityName: String } val AnyCategory = new Category { - def name: String = "match-all" + val entityName: String = "match-all" override def equals(that: Any): Boolean = that.isInstanceOf[Category] } } trait MetricGroupFactory { - type Group <: MetricGroupRecorder - def create(config: Config): Group + type GroupRecorder <: MetricGroupRecorder + def create(config: Config): GroupRecorder } diff --git a/kamon-core/src/main/scala/kamon/metrics/MetricsExtension.scala b/kamon-core/src/main/scala/kamon/metrics/MetricsExtension.scala index 4d7ff354..a717e25a 100644 --- a/kamon-core/src/main/scala/kamon/metrics/MetricsExtension.scala +++ b/kamon-core/src/main/scala/kamon/metrics/MetricsExtension.scala @@ -33,9 +33,9 @@ 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.Group] = { + 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.Group]) + Some(storage.getOrElseUpdate(MetricGroupIdentity(name, category), category.create(config)).asInstanceOf[category.GroupRecorder]) else None } @@ -53,7 +53,7 @@ class MetricsExtension(val system: ExtendedActorSystem) extends Kamon.Extension } private def shouldTrack(name: String, category: MetricGroupIdentity.Category): Boolean = { - filters.get(category.name).map(filter ⇒ filter.accept(name)).getOrElse(false) + filters.get(category.entityName).map(filter ⇒ filter.accept(name)).getOrElse(false) } def loadFilters(config: Config): Map[String, MetricGroupFilter] = { diff --git a/kamon-core/src/main/scala/kamon/metrics/TraceMetrics.scala b/kamon-core/src/main/scala/kamon/metrics/TraceMetrics.scala new file mode 100644 index 00000000..25ebce00 --- /dev/null +++ b/kamon-core/src/main/scala/kamon/metrics/TraceMetrics.scala @@ -0,0 +1,65 @@ +/* + * ========================================================================================= + * 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.metrics + +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 object ElapsedTime extends MetricIdentity { + val name = "ElapsedTime" + } + + case class HttpClientRequest(name: String) extends MetricIdentity + + class TraceMetricRecorder(val elapsedTime: HighDynamicRangeRecorder, private val segmentRecorderFactory: () ⇒ HighDynamicRangeRecorder) + extends MetricGroupRecorder { + + private val segments = TrieMap[MetricIdentity, HighDynamicRangeRecorder]() + + def record(identity: MetricIdentity, value: Long): Unit = identity match { + case ElapsedTime ⇒ elapsedTime.record(value) + case id: MetricIdentity ⇒ segments.getOrElseUpdate(id, segmentRecorderFactory.apply()).record(value) + } + + def collect: MetricGroupSnapshot = TraceMetricSnapshot(elapsedTime.collect(), + segments.map { case (identity, recorder) ⇒ (identity, recorder.collect()) }.toMap) + } + + case class TraceMetricSnapshot(elapsedTime: MetricSnapshot, segments: Map[MetricIdentity, MetricSnapshot]) + extends MetricGroupSnapshot { + + def metrics: Map[MetricIdentity, MetricSnapshot] = segments + (ElapsedTime -> elapsedTime) + } + + def create(config: Config): TraceMetricRecorder = { + import HighDynamicRangeRecorder.Configuration + + 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)) + } + +} |