mirror of
https://github.com/safing/portbase
synced 2025-09-04 03:29:59 +00:00
Improve metric instance detection and pushing
This commit is contained in:
parent
471c3030b7
commit
75d108001b
3 changed files with 7 additions and 3 deletions
|
@ -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 {
|
||||||
|
|
|
@ -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")
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
Loading…
Add table
Reference in a new issue