diff options
Diffstat (limited to 'kamon-datadog/src/main/scala')
-rw-r--r-- | kamon-datadog/src/main/scala/kamon/datadog/Datadog.scala | 66 | ||||
-rw-r--r-- | kamon-datadog/src/main/scala/kamon/datadog/DatadogMetricsSender.scala | 36 |
2 files changed, 20 insertions, 82 deletions
diff --git a/kamon-datadog/src/main/scala/kamon/datadog/Datadog.scala b/kamon-datadog/src/main/scala/kamon/datadog/Datadog.scala index 596a6765..2648d6ef 100644 --- a/kamon-datadog/src/main/scala/kamon/datadog/Datadog.scala +++ b/kamon-datadog/src/main/scala/kamon/datadog/Datadog.scala @@ -22,11 +22,8 @@ import java.util.concurrent.TimeUnit.MILLISECONDS import akka.actor._ import akka.event.Logging import kamon.Kamon -import kamon.akka.{RouterMetrics, DispatcherMetrics, ActorMetrics} -import kamon.http.HttpServerMetrics -import kamon.metric.UserMetrics.{ UserGauges, UserMinMaxCounters, UserCounters, UserHistograms } +import kamon.util.ConfigTools.Syntax import kamon.metric._ -import kamon.metrics._ import scala.collection.JavaConverters._ import scala.concurrent.duration._ @@ -34,13 +31,10 @@ import scala.concurrent.duration._ object Datadog extends ExtensionId[DatadogExtension] with ExtensionIdProvider { override def lookup(): ExtensionId[_ <: Extension] = Datadog override def createExtension(system: ExtendedActorSystem): DatadogExtension = new DatadogExtension(system) - - trait MetricKeyGenerator { - def generateKey(groupIdentity: MetricGroupIdentity, metricIdentity: MetricIdentity): String - } } class DatadogExtension(system: ExtendedActorSystem) extends Kamon.Extension { + implicit val as = system val log = Logging(system, classOf[DatadogExtension]) log.info("Starting the Kamon(Datadog) extension") @@ -53,57 +47,11 @@ class DatadogExtension(system: ExtendedActorSystem) extends Kamon.Extension { val datadogMetricsListener = buildMetricsListener(tickInterval, flushInterval) - // Subscribe to all user metrics - Kamon(Metrics)(system).subscribe(UserHistograms, "*", datadogMetricsListener, permanently = true) - Kamon(Metrics)(system).subscribe(UserCounters, "*", datadogMetricsListener, permanently = true) - Kamon(Metrics)(system).subscribe(UserMinMaxCounters, "*", datadogMetricsListener, permanently = true) - Kamon(Metrics)(system).subscribe(UserGauges, "*", datadogMetricsListener, permanently = true) - - // Subscribe to server metrics - Kamon(Metrics)(system).subscribe(HttpServerMetrics.category, "*", datadogMetricsListener, permanently = true) - - // Subscribe to Actors - val includedActors = datadogConfig.getStringList("includes.actor").asScala - for (actorPathPattern ← includedActors) { - Kamon(Metrics)(system).subscribe(ActorMetrics, actorPathPattern, datadogMetricsListener, permanently = true) - } - - // Subscribe to Routers - val includedRouters = datadogConfig.getStringList("includes.router").asScala - for (routerPathPattern ← includedRouters) { - Kamon(Metrics)(system).subscribe(RouterMetrics, routerPathPattern, datadogMetricsListener, permanently = true) - } - - // Subscribe to Traces - val includedTraces = datadogConfig.getStringList("includes.trace").asScala - for (tracePathPattern ← includedTraces) { - Kamon(Metrics)(system).subscribe(TraceMetrics, tracePathPattern, datadogMetricsListener, permanently = true) - } - - // Subscribe to Dispatchers - val includedDispatchers = datadogConfig.getStringList("includes.dispatcher").asScala - for (dispatcherPathPattern ← includedDispatchers) { - Kamon(Metrics)(system).subscribe(DispatcherMetrics, dispatcherPathPattern, datadogMetricsListener, permanently = true) - } - - // Subscribe to SystemMetrics - val includeSystemMetrics = datadogConfig.getBoolean("report-system-metrics") - if (includeSystemMetrics) { - //OS - Kamon(Metrics)(system).subscribe(CPUMetrics, "*", datadogMetricsListener, permanently = true) - Kamon(Metrics)(system).subscribe(ProcessCPUMetrics, "*", datadogMetricsListener, permanently = true) - Kamon(Metrics)(system).subscribe(MemoryMetrics, "*", datadogMetricsListener, permanently = true) - Kamon(Metrics)(system).subscribe(NetworkMetrics, "*", datadogMetricsListener, permanently = true) - Kamon(Metrics)(system).subscribe(DiskMetrics, "*", datadogMetricsListener, permanently = true) - Kamon(Metrics)(system).subscribe(ContextSwitchesMetrics, "*", datadogMetricsListener, permanently = true) - Kamon(Metrics)(system).subscribe(LoadAverageMetrics, "*", datadogMetricsListener, permanently = true) - - //JVM - Kamon(Metrics)(system).subscribe(HeapMetrics, "*", datadogMetricsListener, permanently = true) - Kamon(Metrics)(system).subscribe(NonHeapMetrics, "*", datadogMetricsListener, permanently = true) - Kamon(Metrics)(system).subscribe(ThreadMetrics, "*", datadogMetricsListener, permanently = true) - Kamon(Metrics)(system).subscribe(ClassLoadingMetrics, "*", datadogMetricsListener, permanently = true) - Kamon(Metrics)(system).subscribe(GCMetrics, "*", datadogMetricsListener, permanently = true) + val subscriptions = datadogConfig.getConfig("subscriptions") + subscriptions.firstLevelKeys.map { subscriptionCategory ⇒ + subscriptions.getStringList(subscriptionCategory).asScala.foreach { pattern ⇒ + Kamon(Metrics).subscribe(subscriptionCategory, pattern, datadogMetricsListener, permanently = true) + } } def buildMetricsListener(tickInterval: Long, flushInterval: Long): ActorRef = { diff --git a/kamon-datadog/src/main/scala/kamon/datadog/DatadogMetricsSender.scala b/kamon-datadog/src/main/scala/kamon/datadog/DatadogMetricsSender.scala index 195798fe..80d4f098 100644 --- a/kamon-datadog/src/main/scala/kamon/datadog/DatadogMetricsSender.scala +++ b/kamon-datadog/src/main/scala/kamon/datadog/DatadogMetricsSender.scala @@ -20,11 +20,10 @@ import akka.actor.{ ActorSystem, Props, ActorRef, Actor } import akka.io.{ Udp, IO } import java.net.InetSocketAddress import akka.util.ByteString -import kamon.metric.Subscriptions.TickMetricSnapshot +import kamon.metric.SubscriptionsDispatcher.TickMetricSnapshot import java.text.{ DecimalFormatSymbols, DecimalFormat } -import kamon.metric.UserMetrics.UserMetricGroup import kamon.metric.instrument.{ Counter, Histogram } -import kamon.metric.{ MetricIdentity, MetricGroupIdentity } +import kamon.metric.{ MetricKey, Entity } import java.util.Locale class DatadogMetricsSender(remote: InetSocketAddress, maxPacketSizeInBytes: Long) extends Actor with UdpExtensionProvider { @@ -68,17 +67,19 @@ class DatadogMetricsSender(remote: InetSocketAddress, maxPacketSizeInBytes: Long } case cs: Counter.Snapshot ⇒ - val measurementData = formatMeasurement(groupIdentity, metricIdentity, encodeDatadogCounter(cs.count)) - packetBuilder.appendMeasurement(key, measurementData) + if (cs.count > 0) { + val measurementData = formatMeasurement(groupIdentity, metricIdentity, encodeDatadogCounter(cs.count)) + packetBuilder.appendMeasurement(key, measurementData) + } } } packetBuilder.flush() } - def formatMeasurement(groupIdentity: MetricGroupIdentity, metricIdentity: MetricIdentity, measurementData: String): String = + def formatMeasurement(entity: Entity, metricKey: MetricKey, measurementData: String): String = StringBuilder.newBuilder .append(measurementData) - .append(buildIdentificationTag(groupIdentity, metricIdentity)) + .append(buildIdentificationTag(entity, metricKey)) .result() def encodeDatadogTimer(level: Long, count: Long): String = { @@ -88,23 +89,12 @@ class DatadogMetricsSender(remote: InetSocketAddress, maxPacketSizeInBytes: Long def encodeDatadogCounter(count: Long): String = count.toString + "|c" - def buildMetricName(groupIdentity: MetricGroupIdentity, metricIdentity: MetricIdentity): String = - if (isUserMetric(groupIdentity)) - s"$appName.${groupIdentity.category.name}.${groupIdentity.name}" - else - s"$appName.${groupIdentity.category.name}.${metricIdentity.name}" - - def buildIdentificationTag(groupIdentity: MetricGroupIdentity, metricIdentity: MetricIdentity): String = { - if (isUserMetric(groupIdentity)) "" else { - // Make the automatic HTTP trace names a bit more friendly - val normalizedEntityName = groupIdentity.name.replace(": ", ":") - s"|#${groupIdentity.category.name}:${normalizedEntityName}" - } - } + def buildMetricName(entity: Entity, metricKey: MetricKey): String = + s"$appName.${entity.category}.${metricKey.name}" - def isUserMetric(groupIdentity: MetricGroupIdentity): Boolean = groupIdentity match { - case someUserMetric: UserMetricGroup ⇒ true - case everythingElse ⇒ false + def buildIdentificationTag(entity: Entity, metricKey: MetricKey): String = { + val normalizedEntityName = entity.name.replace(": ", ":") + s"|#${entity.category}:${normalizedEntityName}" } } |