diff options
author | joffrey-bion <joffrey.bion@gmail.com> | 2021-02-17 03:06:09 +0100 |
---|---|---|
committer | joffrey-bion <joffrey.bion@gmail.com> | 2021-02-17 03:12:50 +0100 |
commit | 69201f4d314debbb79ca16902e203c2c4987e822 (patch) | |
tree | 65fef04350d88cafed6ceac98dab809464479d30 /sw-server | |
parent | Disable auto-embeds in Discord notifications (diff) | |
download | seven-wonders-69201f4d314debbb79ca16902e203c2c4987e822.tar.gz seven-wonders-69201f4d314debbb79ca16902e203c2c4987e822.tar.bz2 seven-wonders-69201f4d314debbb79ca16902e203c2c4987e822.zip |
Attempt at better "instance" variable for metrics
Diffstat (limited to 'sw-server')
-rw-r--r-- | sw-server/src/main/kotlin/org/luxons/sevenwonders/server/SevenWonders.kt | 14 |
1 files changed, 13 insertions, 1 deletions
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<MeterRegistry>? = 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 } } |