aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafael Chacon <rchacon@myfitnesspal.com>2014-08-26 10:09:22 -0700
committerRafael Chacon <rchacon@myfitnesspal.com>2014-08-26 10:09:22 -0700
commit9d13ae86dab7f147d95131e84a56b037ae06f118 (patch)
treee9a0c8ec19f1ec7c3843384ddbf6976e516e82a1
parentbe65d54a8c120343f87f07f617b296bfc5442625 (diff)
downloadKamon-9d13ae86dab7f147d95131e84a56b037ae06f118.tar.gz
Kamon-9d13ae86dab7f147d95131e84a56b037ae06f118.tar.bz2
Kamon-9d13ae86dab7f147d95131e84a56b037ae06f118.zip
+ statsd: add hostname-override to statsd config options.
* This setting allows users to override the hostname used by Kamon when sending metrics to statsd.
-rw-r--r--kamon-statsd/src/main/resources/reference.conf4
-rw-r--r--kamon-statsd/src/main/scala/kamon/statsd/StatsD.scala9
-rw-r--r--kamon-statsd/src/test/scala/kamon/statsd/StatsDMetricSenderSpec.scala23
3 files changed, 35 insertions, 1 deletions
diff --git a/kamon-statsd/src/main/resources/reference.conf b/kamon-statsd/src/main/resources/reference.conf
index f86052c1..c7229234 100644
--- a/kamon-statsd/src/main/resources/reference.conf
+++ b/kamon-statsd/src/main/resources/reference.conf
@@ -37,6 +37,10 @@ kamon {
# will look as follows:
# application.entity.entity-name.metric-name
include-hostname = true
+ # Allow users to override the name of the hostname reported by kamon. When changed, the scheme for the metrics
+ # will have the following pattern:
+ # application.myhostname.entity.entity-name.metric-name
+ hostname-override = "none"
}
}
} \ 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 76ef8d5f..a8d8ae48 100644
--- a/kamon-statsd/src/main/scala/kamon/statsd/StatsD.scala
+++ b/kamon-statsd/src/main/scala/kamon/statsd/StatsD.scala
@@ -107,6 +107,9 @@ 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 hostnameOverride =
+ config.getString("kamon.statsd.simple-metric-key-generator.hostname-override")
+
val _localhostName = ManagementFactory.getRuntimeMXBean.getName.split('@')(1)
val _normalizedLocalhostName = _localhostName.replace('.', '_')
@@ -114,8 +117,12 @@ class SimpleMetricKeyGenerator(config: Config) extends StatsD.MetricKeyGenerator
def normalizedLocalhostName: String = _normalizedLocalhostName
+ val hostname: String =
+ if (hostnameOverride == "none") normalizedLocalhostName
+ else hostnameOverride
+
val baseName: String =
- if (includeHostnameInMetrics) s"${application}.${normalizedLocalhostName}"
+ if (includeHostnameInMetrics) s"${application}.${hostname}"
else application
def generateKey(groupIdentity: MetricGroupIdentity, metricIdentity: MetricIdentity): String = {
diff --git a/kamon-statsd/src/test/scala/kamon/statsd/StatsDMetricSenderSpec.scala b/kamon-statsd/src/test/scala/kamon/statsd/StatsDMetricSenderSpec.scala
index 5f3934a5..28ead7dc 100644
--- a/kamon-statsd/src/test/scala/kamon/statsd/StatsDMetricSenderSpec.scala
+++ b/kamon-statsd/src/test/scala/kamon/statsd/StatsDMetricSenderSpec.scala
@@ -39,6 +39,7 @@ class StatsDMetricSenderSpec extends TestKitBase with WordSpecLike with Matchers
|
| statsd {
| max-packet-size = 256 bytes
+ | simple-metric-key-generator.hostname-override = "none"
| }
|}
|
@@ -51,6 +52,26 @@ class StatsDMetricSenderSpec extends TestKitBase with WordSpecLike with Matchers
val collectionContext = Kamon(Metrics).buildDefaultCollectionContext
"the StatsDMetricSender" should {
+ "allows to override the hostname" in new UdpListenerFixture {
+ val config = ConfigFactory.parseString(
+ """
+ |kamon {
+ | statsd {
+ | simple-metric-key-generator.application = "api"
+ | simple-metric-key-generator.hostname-override = "kamonhost"
+ | simple-metric-key-generator.include-hostname = true
+ | }
+ |}
+ |
+ """.stripMargin)
+ implicit val metricKeyGenerator = new SimpleMetricKeyGenerator(config) {
+ override def normalizedLocalhostName: String = "localhost_local"
+ }
+
+ val testMetricKey = buildMetricKey("trace", "POST: /kamon/example", "elapsed-time")
+ testMetricKey should be(s"api.kamonhost.trace.POST-_kamon_example.elapsed-time")
+ }
+
"removes host name when attribute 'include-hostname' is set to false" in new UdpListenerFixture {
val config = ConfigFactory.parseString(
"""
@@ -58,6 +79,7 @@ class StatsDMetricSenderSpec extends TestKitBase with WordSpecLike with Matchers
| statsd {
| simple-metric-key-generator.application = "api"
| simple-metric-key-generator.include-hostname = false
+ | simple-metric-key-generator.hostname-override = "none"
| }
|}
|
@@ -77,6 +99,7 @@ class StatsDMetricSenderSpec extends TestKitBase with WordSpecLike with Matchers
| statsd {
| simple-metric-key-generator.application = "api"
| simple-metric-key-generator.include-hostname = true
+ | simple-metric-key-generator.hostname-override = "none"
| }
|}
|