diff options
Diffstat (limited to 'kamon-statsd/src/main/scala/kamon/statsd')
-rw-r--r-- | kamon-statsd/src/main/scala/kamon/statsd/StatsD.scala | 26 | ||||
-rw-r--r-- | kamon-statsd/src/main/scala/kamon/statsd/StatsDMetricsSender.scala | 7 |
2 files changed, 24 insertions, 9 deletions
diff --git a/kamon-statsd/src/main/scala/kamon/statsd/StatsD.scala b/kamon-statsd/src/main/scala/kamon/statsd/StatsD.scala index dcd78f78..299b1acc 100644 --- a/kamon-statsd/src/main/scala/kamon/statsd/StatsD.scala +++ b/kamon-statsd/src/main/scala/kamon/statsd/StatsD.scala @@ -32,6 +32,8 @@ object StatsD extends ExtensionId[StatsDExtension] with ExtensionIdProvider { override def createExtension(system: ExtendedActorSystem): StatsDExtension = new StatsDExtension(system) trait MetricKeyGenerator { + def localhostName: String + def normalizedLocalhostName: String def generateKey(groupIdentity: MetricGroupIdentity, metricIdentity: MetricIdentity): String } } @@ -69,22 +71,34 @@ class StatsDExtension(system: ExtendedActorSystem) extends Kamon.Extension { def buildMetricsListener(tickInterval: Long, flushInterval: Long): ActorRef = { assert(flushInterval >= tickInterval, "StatsD flush-interval needs to be equal or greater to the tick-interval") + val defaultMetricKeyGenerator = new SimpleMetricKeyGenerator(system.settings.config) + + val metricsSender = system.actorOf(StatsDMetricsSender.props( + statsDHost, + maxPacketSizeInBytes, + defaultMetricKeyGenerator), "statsd-metrics-sender") - val metricsTranslator = system.actorOf(StatsDMetricsSender.props(statsDHost, maxPacketSizeInBytes), "statsd-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), "statsd-metrics-buffer") + system.actorOf(TickMetricSnapshotBuffer.props(flushInterval.toInt.millis, metricsSender), "statsd-metrics-buffer") } } } class SimpleMetricKeyGenerator(config: Config) extends StatsD.MetricKeyGenerator { val application = config.getString("kamon.statsd.simple-metric-key-generator.application") - val localhostName = ManagementFactory.getRuntimeMXBean.getName.split('@')(1) + val _localhostName = ManagementFactory.getRuntimeMXBean.getName.split('@')(1) + val _normalizedLocalhostName = _localhostName.replace('.', '_') + + def localhostName: String = _localhostName - def generateKey(groupIdentity: MetricGroupIdentity, metricIdentity: MetricIdentity): String = - s"${application}.${localhostName}.${groupIdentity.category.name}.${groupIdentity.name}.${metricIdentity.name}" + def normalizedLocalhostName: String = _normalizedLocalhostName + + def generateKey(groupIdentity: MetricGroupIdentity, metricIdentity: MetricIdentity): String = { + val normalizedGroupName = groupIdentity.name.replace(": ", "-").replace(" ", "_").replace("/", "_") + s"${application}.${normalizedLocalhostName}.${groupIdentity.category.name}.${normalizedGroupName}.${metricIdentity.name}" + } } diff --git a/kamon-statsd/src/main/scala/kamon/statsd/StatsDMetricsSender.scala b/kamon-statsd/src/main/scala/kamon/statsd/StatsDMetricsSender.scala index 94bab27c..8fbf4fee 100644 --- a/kamon-statsd/src/main/scala/kamon/statsd/StatsDMetricsSender.scala +++ b/kamon-statsd/src/main/scala/kamon/statsd/StatsDMetricsSender.scala @@ -26,10 +26,10 @@ import java.util.Locale import kamon.metric.instrument.{ Counter, Histogram } -class StatsDMetricsSender(remote: InetSocketAddress, maxPacketSizeInBytes: Long) extends Actor with UdpExtensionProvider { +class StatsDMetricsSender(remote: InetSocketAddress, maxPacketSizeInBytes: Long, metricKeyGenerator: StatsD.MetricKeyGenerator) + extends Actor with UdpExtensionProvider { import context.system - val metricKeyGenerator = new SimpleMetricKeyGenerator(context.system.settings.config) val symbols = DecimalFormatSymbols.getInstance(Locale.US) symbols.setDecimalSeparator('.') // Just in case there is some weird locale config we are not aware of. @@ -80,7 +80,8 @@ class StatsDMetricsSender(remote: InetSocketAddress, maxPacketSizeInBytes: Long) } object StatsDMetricsSender { - def props(remote: InetSocketAddress, maxPacketSize: Long): Props = Props(new StatsDMetricsSender(remote, maxPacketSize)) + def props(remote: InetSocketAddress, maxPacketSize: Long, metricKeyGenerator: StatsD.MetricKeyGenerator): Props = + Props(new StatsDMetricsSender(remote, maxPacketSize, metricKeyGenerator)) } trait UdpExtensionProvider { |