aboutsummaryrefslogtreecommitdiff
path: root/kamon-newrelic/src/main/scala/kamon/newrelic/CustomMetricExtractor.scala
diff options
context:
space:
mode:
Diffstat (limited to 'kamon-newrelic/src/main/scala/kamon/newrelic/CustomMetricExtractor.scala')
-rw-r--r--kamon-newrelic/src/main/scala/kamon/newrelic/CustomMetricExtractor.scala30
1 files changed, 21 insertions, 9 deletions
diff --git a/kamon-newrelic/src/main/scala/kamon/newrelic/CustomMetricExtractor.scala b/kamon-newrelic/src/main/scala/kamon/newrelic/CustomMetricExtractor.scala
index 6919a967..012ae1dc 100644
--- a/kamon-newrelic/src/main/scala/kamon/newrelic/CustomMetricExtractor.scala
+++ b/kamon-newrelic/src/main/scala/kamon/newrelic/CustomMetricExtractor.scala
@@ -16,22 +16,34 @@
package kamon.newrelic
-import kamon.metric.{ EntitySnapshot, Entity }
+import kamon.metric.{ MetricKey, EntitySnapshot, Entity }
import kamon.metric.instrument.CollectionContext
object CustomMetricExtractor extends MetricExtractor {
def extract(settings: AgentSettings, collectionContext: CollectionContext, metrics: Map[Entity, EntitySnapshot]): Map[MetricID, MetricData] = {
- def onlySimpleMetrics(kv: (Entity, EntitySnapshot)): Boolean =
- kamon.metric.SingleInstrumentEntityRecorder.AllCategories.contains(kv._1.category)
+ val (simple, complex) = metrics filter customMetric partition simpleMetrics
+ simple.flatMap(toNewRelicMetric(simpleName)) ++ complex.flatMap(toNewRelicMetric(complexName))
+ }
+
+ def simpleName(entity: Entity, metricKey: MetricKey) = s"Custom/${entity.category}/${normalize(entity.name)}"
+
+ def complexName(entity: Entity, metricKey: MetricKey) = s"${simpleName(entity, metricKey)}/${metricKey.name}"
- def toNewRelicMetric(kv: (Entity, EntitySnapshot)): (MetricID, MetricData) = {
- val (entity, entitySnapshot) = kv
- val (metricKey, instrumentSnapshot) = entitySnapshot.metrics.head
+ def normalize(name: String) = name.replace('/', '#').replaceAll("""[\]\[\|\*]""", "_")
- Metric(instrumentSnapshot, metricKey.unitOfMeasurement, s"Custom/${entity.name}", None)
- }
+ def customMetric(kv: (Entity, EntitySnapshot)): Boolean =
+ !MetricsSubscription.isTraceOrSegmentEntityName(kv._1.category)
- metrics.filter(onlySimpleMetrics).map(toNewRelicMetric)
+ def simpleMetrics(kv: (Entity, EntitySnapshot)): Boolean =
+ kamon.metric.SingleInstrumentEntityRecorder.AllCategories.contains(kv._1.category)
+
+ def toNewRelicMetric(name: (Entity, MetricKey) ⇒ String)(kv: (Entity, EntitySnapshot)) = {
+ val (entity, entitySnapshot) = kv
+ for {
+ (metricKey, instrumentSnapshot) ← entitySnapshot.metrics
+ nameStr = name(entity, metricKey)
+ } yield Metric(instrumentSnapshot, metricKey.unitOfMeasurement, nameStr, None)
}
+
}