diff options
author | Diego <diegolparra@gmail.com> | 2014-08-29 02:33:04 -0300 |
---|---|---|
committer | Diego <diegolparra@gmail.com> | 2014-08-29 02:33:04 -0300 |
commit | 50d89e2a25b331e953a03ad8d91a18b9e8c0b121 (patch) | |
tree | 417637c3ac48d7afc754e5eeadd3a7067275bde0 /kamon-core/src/main/scala/kamon/metric/RouterMetrics.scala | |
parent | 5ead4817f1bdfbfe6c46d9c70fd08a69623d90ac (diff) | |
download | Kamon-50d89e2a25b331e953a03ad8d91a18b9e8c0b121.tar.gz Kamon-50d89e2a25b331e953a03ad8d91a18b9e8c0b121.tar.bz2 Kamon-50d89e2a25b331e953a03ad8d91a18b9e8c0b121.zip |
+ core: provide metrics for routers
* processing-time
* errors
* time-in-mailbox
closes #62
Diffstat (limited to 'kamon-core/src/main/scala/kamon/metric/RouterMetrics.scala')
-rw-r--r-- | kamon-core/src/main/scala/kamon/metric/RouterMetrics.scala | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/kamon-core/src/main/scala/kamon/metric/RouterMetrics.scala b/kamon-core/src/main/scala/kamon/metric/RouterMetrics.scala new file mode 100644 index 00000000..adb2a18b --- /dev/null +++ b/kamon-core/src/main/scala/kamon/metric/RouterMetrics.scala @@ -0,0 +1,85 @@ +/* + * ========================================================================================= + * Copyright © 2013-2014 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 akka.actor.ActorSystem +import com.typesafe.config.Config +<<<<<<< Updated upstream +import kamon.metric.instrument.{ Counter, Histogram } +======= +import kamon.metric.instrument.{Counter, Histogram} +>>>>>>> Stashed changes + +case class RouterMetrics(name: String) extends MetricGroupIdentity { + val category = RouterMetrics +} + +object RouterMetrics extends MetricGroupCategory { + val name = "router" + + case object ProcessingTime extends MetricIdentity { val name = "processing-time" } + case object TimeInMailbox extends MetricIdentity { val name = "time-in-mailbox" } + case object Errors extends MetricIdentity { val name = "errors" } + + case class RouterMetricsRecorder(processingTime: Histogram, timeInMailbox: Histogram, errors: Counter) extends MetricGroupRecorder { + + def collect(context: CollectionContext): RouterMetricSnapshot = + RouterMetricSnapshot(processingTime.collect(context), timeInMailbox.collect(context), errors.collect(context)) + + def cleanup: Unit = { + processingTime.cleanup + timeInMailbox.cleanup + errors.cleanup + } + } + + case class RouterMetricSnapshot(processingTime: Histogram.Snapshot, timeInMailbox: Histogram.Snapshot, +<<<<<<< Updated upstream + errors: Counter.Snapshot) extends MetricGroupSnapshot { +======= + errors: Counter.Snapshot) extends MetricGroupSnapshot { +>>>>>>> Stashed changes + + type GroupSnapshotType = RouterMetricSnapshot + + def merge(that: RouterMetricSnapshot, context: CollectionContext): RouterMetricSnapshot = + RouterMetricSnapshot( + processingTime.merge(that.processingTime, context), + timeInMailbox.merge(that.timeInMailbox, context), + errors.merge(that.errors, context)) + + lazy val metrics: Map[MetricIdentity, MetricSnapshot] = Map( + ProcessingTime -> processingTime, + TimeInMailbox -> timeInMailbox, + Errors -> errors) + } + + val Factory = new MetricGroupFactory { + type GroupRecorder = RouterMetricsRecorder + + def create(config: Config, system: ActorSystem): RouterMetricsRecorder = { + val settings = config.getConfig("precision.router") + + val processingTimeConfig = settings.getConfig("processing-time") + val timeInMailboxConfig = settings.getConfig("time-in-mailbox") + + new RouterMetricsRecorder( + Histogram.fromConfig(processingTimeConfig), + Histogram.fromConfig(timeInMailboxConfig), + Counter()) + } + } +} |