From d2e02ed36daf508d20fccd5f881fcd057c16003e Mon Sep 17 00:00:00 2001 From: Holger Obermaier <40787752+ho-ob@users.noreply.github.com> Date: Fri, 28 Jan 2022 19:31:27 +0100 Subject: [PATCH] Fix: Add missing hostname tag --- internal/metricRouter/metricRouter.go | 12 ++++++++++++ metric-collector.go | 9 --------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/internal/metricRouter/metricRouter.go b/internal/metricRouter/metricRouter.go index 956ac11..e75e77d 100644 --- a/internal/metricRouter/metricRouter.go +++ b/internal/metricRouter/metricRouter.go @@ -3,6 +3,7 @@ package metricRouter import ( "encoding/json" "os" + "strings" "sync" "time" @@ -29,6 +30,7 @@ type metricRouterConfig struct { // Metric router data structure type metricRouter struct { + hostname string // Hostname used in tags coll_input chan lp.CCMetric // Input channel from CollectorManager recv_input chan lp.CCMetric // Input channel from ReceiveManager outputs []chan lp.CCMetric // List of all output channels @@ -62,6 +64,15 @@ func (r *metricRouter) Init(ticker mct.MultiChanTicker, wg *sync.WaitGroup, rout r.wg = wg r.ticker = ticker + // Set hostname + hostname, err := os.Hostname() + if err != nil { + cclog.Error(err.Error()) + return err + } + // Drop domain part of host name + r.hostname = strings.SplitN(hostname, `.`, 2)[0] + // Read metric router config file configFile, err := os.Open(routerConfigFile) if err != nil { @@ -209,6 +220,7 @@ func (r *metricRouter) Start() { case p := <-r.coll_input: // receive from metric collector + p.AddTag("hostname", r.hostname) if r.config.IntervalStamp { p.SetTime(r.timestamp) } diff --git a/metric-collector.go b/metric-collector.go index 3975b62..b709512 100644 --- a/metric-collector.go +++ b/metric-collector.go @@ -5,7 +5,6 @@ import ( "flag" "os" "os/signal" - "strings" "syscall" "github.com/ClusterCockpit/cc-metric-collector/collectors" @@ -45,7 +44,6 @@ func LoadCentralConfiguration(file string, config *CentralConfigFile) error { } type RuntimeConfig struct { - Hostname string Interval time.Duration Duration time.Duration CliArgs map[string]string @@ -213,13 +211,6 @@ func mainFunc() int { } rcfg.Duration = time.Duration(rcfg.ConfigFile.Duration) * time.Second - rcfg.Hostname, err = os.Hostname() - if err != nil { - cclog.Error(err.Error()) - return 1 - } - // Drop domain part of host name - rcfg.Hostname = strings.SplitN(rcfg.Hostname, `.`, 2)[0] // err = CreatePidfile(rcfg.CliArgs["pidfile"]) // Set log file