diff options
author | Ivan Topolnjak <ivantopo@gmail.com> | 2015-03-05 23:39:44 +0100 |
---|---|---|
committer | Ivan Topolnjak <ivantopo@gmail.com> | 2015-03-09 23:09:08 +0100 |
commit | 959ce3573253ec4ac5b837d8a9c9e70f1f80bd6b (patch) | |
tree | 27c1fe8f22429fe3820f988ab17caaf8e4a6fa3a /kamon-newrelic/src | |
parent | 69ea63923e0d3697f8ca4c7eb9cb808821832aa2 (diff) | |
download | Kamon-959ce3573253ec4ac5b837d8a9c9e70f1f80bd6b.tar.gz Kamon-959ce3573253ec4ac5b837d8a9c9e70f1f80bd6b.tar.bz2 Kamon-959ce3573253ec4ac5b837d8a9c9e70f1f80bd6b.zip |
! all: introduced support for metric tags.
Diffstat (limited to 'kamon-newrelic/src')
3 files changed, 43 insertions, 39 deletions
diff --git a/kamon-newrelic/src/main/scala/kamon/newrelic/CustomMetricExtractor.scala b/kamon-newrelic/src/main/scala/kamon/newrelic/CustomMetricExtractor.scala index 41ed9661..6919a967 100644 --- a/kamon-newrelic/src/main/scala/kamon/newrelic/CustomMetricExtractor.scala +++ b/kamon-newrelic/src/main/scala/kamon/newrelic/CustomMetricExtractor.scala @@ -16,17 +16,22 @@ package kamon.newrelic -import kamon.metric.{ SimpleMetricsImpl, EntitySnapshot, Entity } +import kamon.metric.{ EntitySnapshot, Entity } import kamon.metric.instrument.CollectionContext object CustomMetricExtractor extends MetricExtractor { def extract(settings: AgentSettings, collectionContext: CollectionContext, metrics: Map[Entity, EntitySnapshot]): Map[MetricID, MetricData] = { - metrics.get(SimpleMetricsImpl.SimpleMetricsEntity).map { allSimpleMetrics ⇒ - allSimpleMetrics.metrics.map { - case (key, snapshot) ⇒ Metric(snapshot, key.unitOfMeasurement, s"Custom/${key.name}", None) - } + def onlySimpleMetrics(kv: (Entity, EntitySnapshot)): Boolean = + kamon.metric.SingleInstrumentEntityRecorder.AllCategories.contains(kv._1.category) - } getOrElse (Map.empty) + def toNewRelicMetric(kv: (Entity, EntitySnapshot)): (MetricID, MetricData) = { + val (entity, entitySnapshot) = kv + val (metricKey, instrumentSnapshot) = entitySnapshot.metrics.head + + Metric(instrumentSnapshot, metricKey.unitOfMeasurement, s"Custom/${entity.name}", None) + } + + metrics.filter(onlySimpleMetrics).map(toNewRelicMetric) } } diff --git a/kamon-newrelic/src/main/scala/kamon/newrelic/WebTransactionMetricExtractor.scala b/kamon-newrelic/src/main/scala/kamon/newrelic/WebTransactionMetricExtractor.scala index d0144f4b..76cf0757 100644 --- a/kamon-newrelic/src/main/scala/kamon/newrelic/WebTransactionMetricExtractor.scala +++ b/kamon-newrelic/src/main/scala/kamon/newrelic/WebTransactionMetricExtractor.scala @@ -17,6 +17,7 @@ package kamon.newrelic import kamon.metric.{ EntitySnapshot, Entity } +import kamon.trace.SegmentCategory import scala.collection.mutable import kamon.metric.instrument.{ Time, CollectionContext, Histogram } @@ -35,38 +36,36 @@ object WebTransactionMetricExtractor extends MetricExtractor { val externalScopedByHostAndLibrarySnapshots = mutable.Map.empty[(String, String, String), List[Histogram.Snapshot]] val transactionMetrics = metrics.filterKeys(_.category == "trace").map { - case (entity: Entity, es: EntitySnapshot) ⇒ - // Trace metrics only have elapsed-time and segments and all of them are Histograms. - es.histograms.foreach { - case (key, segmentSnapshot) if key.metadata.get("category").filter(_ == "http-client").nonEmpty ⇒ - val library = key.metadata("library") - accumulatedExternalServices = accumulatedExternalServices.merge(segmentSnapshot, collectionContext) - - // Accumulate externals by host - externalByHostSnapshots.update(key.name, segmentSnapshot :: externalByHostSnapshots.getOrElse(key.name, Nil)) + case (entity, entitySnapshot) ⇒ + val elapsedTime = entitySnapshot.histogram("elapsed-time").get + accumulatedHttpDispatcher = accumulatedHttpDispatcher.merge(elapsedTime, collectionContext) + elapsedTime.recordsIterator.foreach { record ⇒ + apdexBuilder.record(Time.Nanoseconds.scale(Time.Seconds)(record.level), record.count) + } - // Accumulate externals by host and library - externalByHostAndLibrarySnapshots.update((key.name, library), - segmentSnapshot :: externalByHostAndLibrarySnapshots.getOrElse((key.name, library), Nil)) + Metric(elapsedTime, Time.Nanoseconds, "WebTransaction/Custom/" + entity.name, None) + } - // Accumulate externals by host and library, including the transaction as scope. - externalScopedByHostAndLibrarySnapshots.update((key.name, library, entity.name), - segmentSnapshot :: externalScopedByHostAndLibrarySnapshots.getOrElse((key.name, library, entity.name), Nil)) + // Accumulate all segment metrics + metrics.filterKeys(_.category == "trace-segment").map { + case (entity, entitySnapshot) if entity.tags("category") == SegmentCategory.HttpClient ⇒ + val library = entity.tags("library") + val trace = entity.tags("trace") + val elapsedTime = entitySnapshot.histogram("elapsed-time").get - case otherSegments ⇒ + accumulatedExternalServices = accumulatedExternalServices.merge(elapsedTime, collectionContext) - } + // Accumulate externals by host + externalByHostSnapshots.update(entity.name, elapsedTime :: externalByHostSnapshots.getOrElse(entity.name, Nil)) - es.histograms.collect { - case (key, elapsedTime) if key.name == "elapsed-time" ⇒ - accumulatedHttpDispatcher = accumulatedHttpDispatcher.merge(elapsedTime, collectionContext) - elapsedTime.recordsIterator.foreach { record ⇒ - apdexBuilder.record(Time.Nanoseconds.scale(Time.Seconds)(record.level), record.count) - } + // Accumulate externals by host and library + externalByHostAndLibrarySnapshots.update((entity.name, library), + elapsedTime :: externalByHostAndLibrarySnapshots.getOrElse((entity.name, library), Nil)) - Metric(elapsedTime, key.unitOfMeasurement, "WebTransaction/Custom/" + entity.name, None) - } - } flatten + // Accumulate externals by host and library, including the transaction as scope. + externalScopedByHostAndLibrarySnapshots.update((entity.name, library, trace), + elapsedTime :: externalScopedByHostAndLibrarySnapshots.getOrElse((entity.name, library, trace), Nil)) + } val httpDispatcher = Metric(accumulatedHttpDispatcher, Time.Seconds, "HttpDispatcher", None) val webTransaction = httpDispatcher.copy(MetricID("WebTransaction", None)) diff --git a/kamon-newrelic/src/test/scala/kamon/newrelic/MetricReporterSpec.scala b/kamon-newrelic/src/test/scala/kamon/newrelic/MetricReporterSpec.scala index 04380677..d4e815e5 100644 --- a/kamon-newrelic/src/test/scala/kamon/newrelic/MetricReporterSpec.scala +++ b/kamon-newrelic/src/test/scala/kamon/newrelic/MetricReporterSpec.scala @@ -139,19 +139,19 @@ class MetricReporterSpec extends BaseKamonSpec("metric-reporter-spec") with Spra trait FakeTickSnapshotsFixture { val testTraceID = Entity("example-trace", "trace") - val recorder = Kamon.metrics.register(TraceMetrics, testTraceID.name).get.recorder + val recorder = Kamon.metrics.entity(TraceMetrics, testTraceID.name) val collectionContext = Kamon.metrics.buildDefaultCollectionContext def collectRecorder = recorder.collect(collectionContext) - recorder.ElapsedTime.record(1000000) - recorder.ElapsedTime.record(2000000) - recorder.ElapsedTime.record(3000000) + recorder.elapsedTime.record(1000000) + recorder.elapsedTime.record(2000000) + recorder.elapsedTime.record(3000000) val firstSnapshot = TickMetricSnapshot(new MilliTimestamp(1415587618000L), new MilliTimestamp(1415587678000L), Map(testTraceID -> collectRecorder)) - recorder.ElapsedTime.record(6000000) - recorder.ElapsedTime.record(5000000) - recorder.ElapsedTime.record(4000000) + recorder.elapsedTime.record(6000000) + recorder.elapsedTime.record(5000000) + recorder.elapsedTime.record(4000000) val secondSnapshot = TickMetricSnapshot(new MilliTimestamp(1415587678000L), new MilliTimestamp(1415587738000L), Map(testTraceID -> collectRecorder)) } }
\ No newline at end of file |