aboutsummaryrefslogtreecommitdiff
path: root/kamon-newrelic/src/main/scala/kamon/newrelic/CustomMetricExtractor.scala
diff options
context:
space:
mode:
authorSlava Schmidt <slava.schmidt.extern@zalando.de>2015-07-08 12:22:27 +0200
committerSlava Schmidt <slava.schmidt.extern@zalando.de>2015-07-08 12:22:27 +0200
commitf9187cf42a2e6e0815eca4b916729d11b9dda467 (patch)
tree3989360cb0c88540bdb32502254247d1a52b7d0a /kamon-newrelic/src/main/scala/kamon/newrelic/CustomMetricExtractor.scala
parentda471e354ad1757a989ff40c06bafc1f7e332d17 (diff)
downloadKamon-f9187cf42a2e6e0815eca4b916729d11b9dda467.tar.gz
Kamon-f9187cf42a2e6e0815eca4b916729d11b9dda467.tar.bz2
Kamon-f9187cf42a2e6e0815eca4b916729d11b9dda467.zip
+ newrelic: add possibility to send akka metrics to the newrelic
Added possibility to send akka metrics to the newrelic as custom metrics. Externalized categories of newrelic subscription into the configuration file. This allow to define which metrics categories should be send to newrelic independent upon which metrics are actually collected. Akka metrics exported to the newrelic as custom metrics and available in custom dashboards in some format similar to: Cusom/akka-actor/{ActorSystemName[user|system|...]\{ActorName}/{MetricName} for actors and Custom/akka-thread-pool-executor\Some-Service\akka.io.pinned-dispatcher/ProcessedTasks for thread pools. Same metrics for multiple actors can be displayed as a single chart by using * (star) for part of the actor name. For example Cusom/akka-actor\MyActor\user\*DatabaseWorker/ProcessingTime will show processing time for all database workers. Example of actor metrics displayed by newrelic: http://s4.postimg.org/sfn9vjzgt/Screen_Shot_2015_04_22_at_11_24_15.png Example of pool metrics displayed by newrelic: http://s4.postimg.org/gchy7zoel/Screen_Shot_2015_04_22_at_11_24_24.png
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)
}
+
}