From 1ae32d638b7ded29db9976fe5e00146d705c8a13 Mon Sep 17 00:00:00 2001 From: Niko Storni Date: Tue, 19 May 2020 23:24:16 +0200 Subject: [PATCH] fix prom allowed chars --- metrics/metrics.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/metrics/metrics.go b/metrics/metrics.go index 1b5fb12..c978430 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -2,9 +2,11 @@ package metrics import ( "os" + "regexp" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" + log "github.com/sirupsen/logrus" ) var ( @@ -19,7 +21,11 @@ var ( func getHostname() string { hostname, err := os.Hostname() if err != nil { - hostname = "ytsync-unknown" + hostname = "ytsync_unknown" } - return hostname + reg, err := regexp.Compile("[^a-zA-Z0-9_]+") + if err != nil { + log.Fatal(err) + } + return reg.ReplaceAllString(hostname, "_") }