From 1c3e6490980eb2fde09f9befb8db604d1c085eee Mon Sep 17 00:00:00 2001 From: Evan Phoenix Date: Tue, 7 Apr 2015 09:56:40 -0700 Subject: [PATCH] Automatically include a 'host' tag --- agent.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/agent.go b/agent.go index e8bc7f5cb..976fd7b3f 100644 --- a/agent.go +++ b/agent.go @@ -3,6 +3,7 @@ package tivan import ( "log" "net/url" + "os" "sort" "time" @@ -14,6 +15,7 @@ type Agent struct { Interval Duration Debug bool HTTP string + Hostname string Config *Config @@ -30,6 +32,21 @@ func NewAgent(config *Config) (*Agent, error) { return nil, err } + if agent.Hostname == "" { + hostname, err := os.Hostname() + if err != nil { + return nil, err + } + + agent.Hostname = hostname + + if config.Tags == nil { + config.Tags = map[string]string{} + } + + config.Tags["host"] = agent.Hostname + } + return agent, nil }