From 69201f4d314debbb79ca16902e203c2c4987e822 Mon Sep 17 00:00:00 2001 From: joffrey-bion Date: Wed, 17 Feb 2021 03:06:09 +0100 Subject: Attempt at better "instance" variable for metrics --- .../kotlin/org/luxons/sevenwonders/server/SevenWonders.kt | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'sw-server/src/main/kotlin/org/luxons') diff --git a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/SevenWonders.kt b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/SevenWonders.kt index 923ebcb5..93ff0be7 100644 --- a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/SevenWonders.kt +++ b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/SevenWonders.kt @@ -21,7 +21,19 @@ class SevenWonders { fun metricsCommonTags(): MeterRegistryCustomizer? = MeterRegistryCustomizer { registry -> registry.config() .commonTags("application", "seven-wonders") - .commonTags("instance", InetAddress.getLocalHost().hostAddress) + .commonTags("instance", findInstanceName()) + } + + private fun findInstanceName(): String? { + val hostname = System.getenv("HOSTNAME")?.takeIf { it.isNotBlank() } + if (hostname != null) { + return hostname + } + val computerName = System.getenv("COMPUTERNAME")?.takeIf { it.isNotBlank() } + if (computerName != null) { + return computerName + } + return InetAddress.getLocalHost().hostName } } -- cgit