diff options
author | Ivan Topolnak <itopolnak@despegar.com> | 2014-03-06 18:08:59 -0300 |
---|---|---|
committer | Ivan Topolnak <itopolnak@despegar.com> | 2014-03-06 18:08:59 -0300 |
commit | eb7c41c17ced2a749fe2c63794531f067d76ea7b (patch) | |
tree | 2c1cca7523c67d79c5be63f3cd9fac70aed09645 /kamon-core/src/main/scala/kamon/metrics | |
parent | da2ba240b2202639cae75928232f3f39228dbc3d (diff) | |
download | Kamon-eb7c41c17ced2a749fe2c63794531f067d76ea7b.tar.gz Kamon-eb7c41c17ced2a749fe2c63794531f067d76ea7b.tar.bz2 Kamon-eb7c41c17ced2a749fe2c63794531f067d76ea7b.zip |
support for custom metrics
Diffstat (limited to 'kamon-core/src/main/scala/kamon/metrics')
4 files changed, 62 insertions, 4 deletions
diff --git a/kamon-core/src/main/scala/kamon/metrics/ActorMetrics.scala b/kamon-core/src/main/scala/kamon/metrics/ActorMetrics.scala index 4c8752e5..b3685a93 100644 --- a/kamon-core/src/main/scala/kamon/metrics/ActorMetrics.scala +++ b/kamon-core/src/main/scala/kamon/metrics/ActorMetrics.scala @@ -32,7 +32,7 @@ object ActorMetrics extends MetricGroupCategory { case object TimeInMailbox extends MetricIdentity { val name, tag = "TimeInMailbox" } case class ActorMetricRecorder(processingTime: MetricRecorder, mailboxSize: MetricRecorder, timeInMailbox: MetricRecorder) - extends MetricGroupRecorder { + extends MetricMultiGroupRecorder { def record(identity: MetricIdentity, value: Long): Unit = identity match { case ProcessingTime ⇒ processingTime.record(value) diff --git a/kamon-core/src/main/scala/kamon/metrics/CustomMetric.scala b/kamon-core/src/main/scala/kamon/metrics/CustomMetric.scala new file mode 100644 index 00000000..11cb6c3d --- /dev/null +++ b/kamon-core/src/main/scala/kamon/metrics/CustomMetric.scala @@ -0,0 +1,51 @@ +/* + * ========================================================================================= + * 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 kamon.metrics.instruments.ContinuousHighDynamicRangeRecorder +import org.HdrHistogram.HighDynamicRangeRecorder.Configuration +import org.HdrHistogram.HighDynamicRangeRecorder +import com.typesafe.config.Config + +case class CustomMetric(name: String) extends MetricGroupIdentity { + val category = CustomMetric +} + +object CustomMetric extends MetricGroupCategory { + val name = "custom-metric" + private val identity = new MetricIdentity { val name, tag = "RecordedValues" } + + def withConfig(highestTrackableValue: Long, significantValueDigits: Int, continuous: Boolean = false) = new MetricGroupFactory { + type GroupRecorder = CustomMetricRecorder + + def create(config: Config): CustomMetricRecorder = + if (continuous) + new CustomMetricRecorder(identity, ContinuousHighDynamicRangeRecorder(Configuration(highestTrackableValue, significantValueDigits))) + else + new CustomMetricRecorder(identity, HighDynamicRangeRecorder(Configuration(highestTrackableValue, significantValueDigits))) + } + + class CustomMetricRecorder(identity: MetricIdentity, underlyingRecorder: HighDynamicRangeRecorder) + extends MetricSingleGroupRecorder { + + def collect: MetricGroupSnapshot = new MetricGroupSnapshot { + val metrics: Map[MetricIdentity, MetricSnapshot] = Map((identity, underlyingRecorder.collect())) + } + + def record(value: Long): Unit = underlyingRecorder.record(value) + } +} diff --git a/kamon-core/src/main/scala/kamon/metrics/Metrics.scala b/kamon-core/src/main/scala/kamon/metrics/Metrics.scala index 81475d52..f7ee833b 100644 --- a/kamon-core/src/main/scala/kamon/metrics/Metrics.scala +++ b/kamon-core/src/main/scala/kamon/metrics/Metrics.scala @@ -34,11 +34,18 @@ trait MetricIdentity { def tag: String } -trait MetricGroupRecorder { - def record(identity: MetricIdentity, value: Long) +sealed trait MetricGroupRecorder { def collect: MetricGroupSnapshot } +trait MetricMultiGroupRecorder extends MetricGroupRecorder { + def record(identity: MetricIdentity, value: Long) +} + +trait MetricSingleGroupRecorder extends MetricGroupRecorder { + def record(value: Long) +} + trait MetricGroupSnapshot { def metrics: Map[MetricIdentity, MetricSnapshot] } diff --git a/kamon-core/src/main/scala/kamon/metrics/TraceMetrics.scala b/kamon-core/src/main/scala/kamon/metrics/TraceMetrics.scala index ccffe382..abea3d82 100644 --- a/kamon-core/src/main/scala/kamon/metrics/TraceMetrics.scala +++ b/kamon-core/src/main/scala/kamon/metrics/TraceMetrics.scala @@ -31,7 +31,7 @@ object TraceMetrics extends MetricGroupCategory { case class HttpClientRequest(name: String, tag: String) extends MetricIdentity class TraceMetricRecorder(val elapsedTime: HighDynamicRangeRecorder, private val segmentRecorderFactory: () ⇒ HighDynamicRangeRecorder) - extends MetricGroupRecorder { + extends MetricMultiGroupRecorder { private val segments = TrieMap[MetricIdentity, HighDynamicRangeRecorder]() |