fix prom allowed chars

This commit is contained in:
Niko Storni 2020-05-19 23:24:16 +02:00
parent 7907ee3579
commit 1ae32d638b

View file

@ -2,9 +2,11 @@ package metrics
import ( import (
"os" "os"
"regexp"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto" "github.com/prometheus/client_golang/prometheus/promauto"
log "github.com/sirupsen/logrus"
) )
var ( var (
@ -19,7 +21,11 @@ var (
func getHostname() string { func getHostname() string {
hostname, err := os.Hostname() hostname, err := os.Hostname()
if err != nil { 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, "_")
} }