From e846b9224bab67bf54ab693ee50b8c28e124e1e3 Mon Sep 17 00:00:00 2001 From: ale <ale@incal.net> Date: Thu, 9 Oct 2014 08:58:25 +0100 Subject: [PATCH] add a hostname prefix to all statsd metrics --- debian/changelog | 6 ++++++ instrumentation/stats.go | 14 +++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index a4ba7d2d..84b624eb 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +autoradio (0.3.2p1) unstable; urgency=medium + + * Instrumentation fix. + + -- ale <ale@incal.net> Thu, 09 Oct 2014 08:45:50 +0100 + autoradio (0.3.2) unstable; urgency=medium * Add statsd instrumentation. diff --git a/instrumentation/stats.go b/instrumentation/stats.go index adcfb65b..333d0b6c 100644 --- a/instrumentation/stats.go +++ b/instrumentation/stats.go @@ -2,7 +2,9 @@ package instrumentation import ( "flag" + "fmt" "log" + "os" "sync" "github.com/cactus/go-statsd-client/statsd" @@ -15,11 +17,21 @@ var ( clientInit sync.Once client *statsd.Client + + prefix string ) +func init() { + hostname, err := os.Hostname() + if err != nil { + log.Fatal("Could not determine hostname: %v", err) + } + prefix = fmt.Sprintf("autoradio.%s.", hostname) +} + func getClient() *statsd.Client { clientInit.Do(func() { - c, err := statsd.New(*statsdServer, "autoradio.") + c, err := statsd.New(*statsdServer, prefix) if err != nil { log.Fatal("Error initializing instrumentation: %v", err) } -- GitLab