Improve metric instance detection and pushing

This commit is contained in:
Daniel 2021-12-22 11:20:18 +01:00
parent 471c3030b7
commit 75d108001b
3 changed files with 7 additions and 3 deletions

View file

@ -120,7 +120,7 @@ func writeMetricsTo(ctx context.Context, url string) error {
func metricsWriter(ctx context.Context) error { func metricsWriter(ctx context.Context) error {
pushURL := pushOption() pushURL := pushOption()
ticker := time.NewTicker(10 * time.Second) ticker := time.NewTicker(1 * time.Minute)
defer ticker.Stop() defer ticker.Stop()
for { for {

View file

@ -3,6 +3,7 @@ package metrics
import ( import (
"flag" "flag"
"os" "os"
"strings"
"github.com/safing/portbase/config" "github.com/safing/portbase/config"
) )
@ -25,7 +26,10 @@ var (
func init() { func init() {
hostname, err := os.Hostname() hostname, err := os.Hostname()
if err == nil { if err == nil {
defaultInstance = hostname hostname = strings.ReplaceAll(hostname, "-", "")
if prometheusFormat.MatchString(hostname) {
defaultInstance = hostname
}
} }
flag.StringVar(&pushFlag, "push-metrics", "", "set default URL to push prometheus metrics to") flag.StringVar(&pushFlag, "push-metrics", "", "set default URL to push prometheus metrics to")

View file

@ -35,7 +35,7 @@ var (
) )
func init() { func init() {
module = modules.Register("metrics", prep, start, stop, "database", "api") module = modules.Register("metrics", prep, start, stop, "config", "database", "api")
} }
func prep() error { func prep() error {