diff options
author | Ivan Topolnjak <ivantopo@gmail.com> | 2014-07-29 02:17:21 -0300 |
---|---|---|
committer | Ivan Topolnjak <ivantopo@gmail.com> | 2014-07-29 02:17:21 -0300 |
commit | 409843750c596d31ce48b606677b1d5224be3880 (patch) | |
tree | b0d9eaec5f62acc223910ad5deafbac23125700a /kamon-datadog/src/main/scala/kamon/datadog | |
parent | 4d336a1d2bd42a84a21e8770d8e0c401f8871aa7 (diff) | |
parent | e83babb5f88e91661bec2f1013fcb6b03612bea9 (diff) | |
download | Kamon-409843750c596d31ce48b606677b1d5224be3880.tar.gz Kamon-409843750c596d31ce48b606677b1d5224be3880.tar.bz2 Kamon-409843750c596d31ce48b606677b1d5224be3880.zip |
Merge branch 'master' into release-0.2
Conflicts:
kamon-core/src/main/scala/kamon/metrics/Subscriptions.scala
kamon-core/src/test/scala/kamon/instrumentation/akka/ActorCellInstrumentationSpec.scala
kamon-datadog/src/main/scala/kamon/datadog/Datadog.scala
kamon-play/src/main/scala/kamon/play/instrumentation/WSInstrumentation.scala
kamon-play/src/test/scala/kamon/play/RequestInstrumentationSpec.scala
kamon-play/src/test/scala/kamon/play/WSInstrumentationSpec.scala
kamon-playground/src/main/scala/test/SimpleRequestProcessor.scala
kamon-statsd/src/main/scala/kamon/statsd/StatsD.scala
project/Projects.scala
version.sbt
Diffstat (limited to 'kamon-datadog/src/main/scala/kamon/datadog')
-rw-r--r-- | kamon-datadog/src/main/scala/kamon/datadog/Datadog.scala | 16 | ||||
-rw-r--r-- | kamon-datadog/src/main/scala/kamon/datadog/DatadogMetricsSender.scala | 54 |
2 files changed, 42 insertions, 28 deletions
diff --git a/kamon-datadog/src/main/scala/kamon/datadog/Datadog.scala b/kamon-datadog/src/main/scala/kamon/datadog/Datadog.scala index 1eb2e8a6..63557781 100644 --- a/kamon-datadog/src/main/scala/kamon/datadog/Datadog.scala +++ b/kamon-datadog/src/main/scala/kamon/datadog/Datadog.scala @@ -18,7 +18,9 @@ package kamon.datadog import akka.actor._ import kamon.Kamon +import kamon.metric._ import kamon.metrics._ +import kamon.metrics.CPUMetrics import scala.concurrent.duration._ import scala.collection.JavaConverters._ import akka.event.Logging @@ -64,15 +66,23 @@ class DatadogExtension(system: ExtendedActorSystem) extends Kamon.Extension { Kamon(Metrics)(system).subscribe(DispatcherMetrics, dispatcherPathPattern, datadogMetricsListener, permanently = true) } + // Subscribe to SystemMetrics + val includeSystemMetrics = datadogConfig.getBoolean("report-system-metrics") + if (includeSystemMetrics) { + List(CPUMetrics, ProcessCPUMetrics, MemoryMetrics, NetworkMetrics, GCMetrics, HeapMetrics) foreach { metric ⇒ + Kamon(Metrics)(system).subscribe(metric, "*", datadogMetricsListener, permanently = true) + } + } + def buildMetricsListener(tickInterval: Long, flushInterval: Long): ActorRef = { assert(flushInterval >= tickInterval, "Datadog flush-interval needs to be equal or greater to the tick-interval") - val metricsTranslator = system.actorOf(DatadogMetricsSender.props(datadogHost, maxPacketSizeInBytes), "datadog-metrics-sender") + val metricsSender = system.actorOf(DatadogMetricsSender.props(datadogHost, maxPacketSizeInBytes), "datadog-metrics-sender") if (flushInterval == tickInterval) { // No need to buffer the metrics, let's go straight to the metrics sender. - metricsTranslator + metricsSender } else { - system.actorOf(TickMetricSnapshotBuffer.props(flushInterval.toInt.millis, metricsTranslator), "datadog-metrics-buffer") + system.actorOf(TickMetricSnapshotBuffer.props(flushInterval.toInt.millis, metricsSender), "datadog-metrics-buffer") } } } diff --git a/kamon-datadog/src/main/scala/kamon/datadog/DatadogMetricsSender.scala b/kamon-datadog/src/main/scala/kamon/datadog/DatadogMetricsSender.scala index 028e9608..0f67cc34 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.metrics.Subscriptions.TickMetricSnapshot -import kamon.metrics.MetricSnapshot.Measurement -import kamon.metrics.InstrumentTypes.{ Counter, Gauge, Histogram, InstrumentType } +import kamon.metric.Subscriptions.TickMetricSnapshot import java.text.{ DecimalFormatSymbols, DecimalFormat } -import kamon.metrics.{ MetricIdentity, MetricGroupIdentity } +import kamon.metric.instrument.{ Counter, Histogram } +import kamon.metric.{ MetricIdentity, MetricGroupIdentity } import java.util.Locale class DatadogMetricsSender(remote: InetSocketAddress, maxPacketSizeInBytes: Long) extends Actor with UdpExtensionProvider { @@ -50,7 +49,7 @@ class DatadogMetricsSender(remote: InetSocketAddress, maxPacketSizeInBytes: Long } def writeMetricsToRemote(tick: TickMetricSnapshot, udpSender: ActorRef): Unit = { - val dataBuilder = new MetricDataPacketBuilder(maxPacketSizeInBytes, udpSender, remote) + val packetBuilder = new MetricDataPacketBuilder(maxPacketSizeInBytes, udpSender, remote) for { (groupIdentity, groupSnapshot) ← tick.metrics @@ -59,38 +58,43 @@ class DatadogMetricsSender(remote: InetSocketAddress, maxPacketSizeInBytes: Long val key = buildMetricName(groupIdentity, metricIdentity) - for (measurement ← metricSnapshot.measurements) { - val measurementData = formatMeasurement(groupIdentity, metricIdentity, measurement, metricSnapshot.instrumentType) - dataBuilder.appendMeasurement(key, measurementData) + metricSnapshot match { + case hs: Histogram.Snapshot ⇒ + hs.recordsIterator.foreach { record ⇒ + val measurementData = formatMeasurement(groupIdentity, metricIdentity, encodeStatsDTimer(record.level, record.count)) + packetBuilder.appendMeasurement(key, measurementData) + + } + + case cs: Counter.Snapshot ⇒ + val measurementData = formatMeasurement(groupIdentity, metricIdentity, encodeStatsDCounter(cs.count)) + packetBuilder.appendMeasurement(key, measurementData) } } - dataBuilder.flush() + packetBuilder.flush() } - def formatMeasurement(groupIdentity: MetricGroupIdentity, metricIdentity: MetricIdentity, measurement: Measurement, - instrumentType: InstrumentType): String = { - - StringBuilder.newBuilder.append(buildMeasurementData(measurement, instrumentType)) + def formatMeasurement(groupIdentity: MetricGroupIdentity, metricIdentity: MetricIdentity, measurementData: String): String = + StringBuilder.newBuilder + .append(measurementData) .append(buildIdentificationTag(groupIdentity, metricIdentity)) .result() - } - def buildMeasurementData(measurement: Measurement, instrumentType: InstrumentType): String = { - def dataDogDMetricFormat(value: String, metricType: String, samplingRate: Double = 1D): String = - s"$value|$metricType${(if (samplingRate != 1D) "|@" + samplingRateFormat.format(samplingRate) else "")}" - - instrumentType match { - case Histogram ⇒ dataDogDMetricFormat(measurement.value.toString, "ms", (1D / measurement.count)) - case Gauge ⇒ dataDogDMetricFormat(measurement.value.toString, "g") - case Counter ⇒ dataDogDMetricFormat(measurement.count.toString, "c") - } + def encodeStatsDTimer(level: Long, count: Long): String = { + val samplingRate: Double = 1D / count + level.toString + "|ms" + (if (samplingRate != 1D) "|@" + samplingRateFormat.format(samplingRate) else "") } + def encodeStatsDCounter(count: Long): String = count.toString + "|c" + def buildMetricName(groupIdentity: MetricGroupIdentity, metricIdentity: MetricIdentity): String = s"$appName.${groupIdentity.category.name}.${metricIdentity.name}" - def buildIdentificationTag(groupIdentity: MetricGroupIdentity, metricIdentity: MetricIdentity): String = - s"|#${groupIdentity.category.name}:${groupIdentity.name}" + def buildIdentificationTag(groupIdentity: MetricGroupIdentity, metricIdentity: MetricIdentity): String = { + // Make the automatic HTTP trace names a bit more friendly + val normalizedEntityName = groupIdentity.name.replace(": ", ":") + s"|#${groupIdentity.category.name}:${normalizedEntityName}" + } } object DatadogMetricsSender { |