diff options
author | Rafael Chacon <rchacon@myfitnesspal.com> | 2014-08-20 07:47:48 -0700 |
---|---|---|
committer | Rafael Chacon <rchacon@myfitnesspal.com> | 2014-08-20 07:47:48 -0700 |
commit | be65d54a8c120343f87f07f617b296bfc5442625 (patch) | |
tree | da551faace02fb0e4cb86881bfb4af37053efdbf /kamon-statsd/src/main | |
parent | bd038442903e9070626ab21b64a4016d2ad5ae6a (diff) | |
download | Kamon-be65d54a8c120343f87f07f617b296bfc5442625.tar.gz Kamon-be65d54a8c120343f87f07f617b296bfc5442625.tar.bz2 Kamon-be65d54a8c120343f87f07f617b296bfc5442625.zip |
+ statsd: add the include-hostname setting to the default key generator
* This commit adds 'include-hostname' the default key generator setting
in statsd. When set to false, the generated keys wont include host
information. They will have the following scheme:
application.entity.entity-name.metric-name
Diffstat (limited to 'kamon-statsd/src/main')
-rw-r--r-- | kamon-statsd/src/main/resources/reference.conf | 4 | ||||
-rw-r--r-- | kamon-statsd/src/main/scala/kamon/statsd/StatsD.scala | 14 |
2 files changed, 13 insertions, 5 deletions
diff --git a/kamon-statsd/src/main/resources/reference.conf b/kamon-statsd/src/main/resources/reference.conf index eac5eade..f86052c1 100644 --- a/kamon-statsd/src/main/resources/reference.conf +++ b/kamon-statsd/src/main/resources/reference.conf @@ -33,6 +33,10 @@ kamon { # this pattern: # application.host.entity.entity-name.metric-name application = "kamon" + # Includes the name of the hostname in the generated metric. When set to false, the scheme for the metrics + # will look as follows: + # application.entity.entity-name.metric-name + include-hostname = true } } }
\ No newline at end of file diff --git a/kamon-statsd/src/main/scala/kamon/statsd/StatsD.scala b/kamon-statsd/src/main/scala/kamon/statsd/StatsD.scala index ff273d9f..76ef8d5f 100644 --- a/kamon-statsd/src/main/scala/kamon/statsd/StatsD.scala +++ b/kamon-statsd/src/main/scala/kamon/statsd/StatsD.scala @@ -105,6 +105,8 @@ class StatsDExtension(system: ExtendedActorSystem) extends Kamon.Extension { class SimpleMetricKeyGenerator(config: Config) extends StatsD.MetricKeyGenerator { val application = config.getString("kamon.statsd.simple-metric-key-generator.application") + val includeHostnameInMetrics = + config.getBoolean("kamon.statsd.simple-metric-key-generator.include-hostname") val _localhostName = ManagementFactory.getRuntimeMXBean.getName.split('@')(1) val _normalizedLocalhostName = _localhostName.replace('.', '_') @@ -112,13 +114,16 @@ class SimpleMetricKeyGenerator(config: Config) extends StatsD.MetricKeyGenerator def normalizedLocalhostName: String = _normalizedLocalhostName + val baseName: String = + if (includeHostnameInMetrics) s"${application}.${normalizedLocalhostName}" + else application + def generateKey(groupIdentity: MetricGroupIdentity, metricIdentity: MetricIdentity): String = { val normalizedGroupName = groupIdentity.name.replace(": ", "-").replace(" ", "_").replace("/", "_") + val key = s"${baseName}.${groupIdentity.category.name}.${normalizedGroupName}" - if (isUserMetric(groupIdentity)) - s"${application}.${normalizedLocalhostName}.${groupIdentity.category.name}.${normalizedGroupName}" - else - s"${application}.${normalizedLocalhostName}.${groupIdentity.category.name}.${normalizedGroupName}.${metricIdentity.name}" + if (isUserMetric(groupIdentity)) key + else s"${key}.${metricIdentity.name}" } def isUserMetric(groupIdentity: MetricGroupIdentity): Boolean = groupIdentity match { @@ -126,4 +131,3 @@ class SimpleMetricKeyGenerator(config: Config) extends StatsD.MetricKeyGenerator case everythingElse ⇒ false } } - |