summaryrefslogtreecommitdiff
path: root/sw-server/src/main/kotlin/org/luxons
diff options
context:
space:
mode:
authorjoffrey-bion <joffrey.bion@gmail.com>2021-02-17 03:06:09 +0100
committerjoffrey-bion <joffrey.bion@gmail.com>2021-02-17 03:12:50 +0100
commit69201f4d314debbb79ca16902e203c2c4987e822 (patch)
tree65fef04350d88cafed6ceac98dab809464479d30 /sw-server/src/main/kotlin/org/luxons
parentDisable auto-embeds in Discord notifications (diff)
downloadseven-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/src/main/kotlin/org/luxons')
-rw-r--r--sw-server/src/main/kotlin/org/luxons/sevenwonders/server/SevenWonders.kt14
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
}
}
bgstack15