Automatically include a 'host' tag

This commit is contained in:
Evan Phoenix 2015-04-07 09:56:40 -07:00
parent 2820c0391e
commit 1c3e649098
1 changed files with 17 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package tivan
import ( import (
"log" "log"
"net/url" "net/url"
"os"
"sort" "sort"
"time" "time"
@ -14,6 +15,7 @@ type Agent struct {
Interval Duration Interval Duration
Debug bool Debug bool
HTTP string HTTP string
Hostname string
Config *Config Config *Config
@ -30,6 +32,21 @@ func NewAgent(config *Config) (*Agent, error) {
return nil, err 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 return agent, nil
} }