diff options
author | Diego <diegolparra@gmail.com> | 2014-10-19 23:17:19 -0300 |
---|---|---|
committer | Diego <diegolparra@gmail.com> | 2014-10-19 23:17:19 -0300 |
commit | cabcd24b92d2ccbb82c24fbf658b2390d6e9cf89 (patch) | |
tree | 51b2d1efc211d85966274b40426367e1eee53015 /kamon-newrelic/src/main/scala/kamon | |
parent | 62d02deec6f21b62ad3c878aad4c0927b7bac1d0 (diff) | |
download | Kamon-cabcd24b92d2ccbb82c24fbf658b2390d6e9cf89.tar.gz Kamon-cabcd24b92d2ccbb82c24fbf658b2390d6e9cf89.tar.bz2 Kamon-cabcd24b92d2ccbb82c24fbf658b2390d6e9cf89.zip |
= kamon-newrelic: minor refactor when merge metrics
Diffstat (limited to 'kamon-newrelic/src/main/scala/kamon')
-rw-r--r-- | kamon-newrelic/src/main/scala/kamon/newrelic/AgentJsonProtocol.scala | 2 | ||||
-rw-r--r-- | kamon-newrelic/src/main/scala/kamon/newrelic/MetricTranslator.scala | 9 |
2 files changed, 7 insertions, 4 deletions
diff --git a/kamon-newrelic/src/main/scala/kamon/newrelic/AgentJsonProtocol.scala b/kamon-newrelic/src/main/scala/kamon/newrelic/AgentJsonProtocol.scala index ecb8ff09..9b3e6dea 100644 --- a/kamon-newrelic/src/main/scala/kamon/newrelic/AgentJsonProtocol.scala +++ b/kamon-newrelic/src/main/scala/kamon/newrelic/AgentJsonProtocol.scala @@ -58,6 +58,6 @@ object AgentJsonProtocol extends DefaultJsonProtocol { JsNumber(obj.runId), JsNumber(obj.timeSliceMetrics.from), JsNumber(obj.timeSliceMetrics.to), - obj.timeSliceMetrics.metrics.toJson) + obj.timeSliceMetrics.metrics.values.toSeq.toJson) } } diff --git a/kamon-newrelic/src/main/scala/kamon/newrelic/MetricTranslator.scala b/kamon-newrelic/src/main/scala/kamon/newrelic/MetricTranslator.scala index 6313a2aa..5fa571e1 100644 --- a/kamon-newrelic/src/main/scala/kamon/newrelic/MetricTranslator.scala +++ b/kamon-newrelic/src/main/scala/kamon/newrelic/MetricTranslator.scala @@ -28,16 +28,19 @@ class MetricTranslator(receiver: ActorRef) extends Actor val fromInSeconds = (from / 1E3).toInt val toInSeconds = (to / 1E3).toInt val allMetrics = collectWebTransactionMetrics(metrics) ++ collectCustomMetrics(metrics) + val groupedMetrics: Map[String, NewRelic.Metric] = allMetrics.map(metric ⇒ metric.name -> metric)(collection.breakOut) // avoid intermediate tuple - receiver ! TimeSliceMetrics(fromInSeconds, toInSeconds, allMetrics) + receiver ! TimeSliceMetrics(fromInSeconds, toInSeconds, groupedMetrics) } } object MetricTranslator { - case class TimeSliceMetrics(from: Long, to: Long, metrics: Seq[NewRelic.Metric]) { + case class TimeSliceMetrics(from: Long, to: Long, metrics: Map[String, NewRelic.Metric]) { + import kamon.metric._ + def merge(thatMetrics: Option[TimeSliceMetrics]): TimeSliceMetrics = { - thatMetrics.map(that ⇒ TimeSliceMetrics(from + that.from, to + that.to, metrics ++ that.metrics)).getOrElse(this) + thatMetrics.map(that ⇒ TimeSliceMetrics(from + that.from, to + that.to, combineMaps(metrics, that.metrics)((l, r) ⇒ l.merge(r)))).getOrElse(this) } } |