add owner (as tag)

This commit is contained in:
Martin Geno 2016-07-09 02:33:34 +02:00
parent 93fe0fadb5
commit c13185fd51
3 changed files with 11 additions and 2 deletions

View File

@ -97,6 +97,10 @@ func onReceive(addr net.UDPAddr, res *data.ResponseData) {
nodes.Update(nodeId, res)
if val := res.Statistics; val != nil && statsDb != nil {
statsDb.Add(val)
if node := res.NodeInfo; val != nil && statsDb != nil {
statsDb.Add(val, node)
} else {
statsDb.Add(val, nil)
}
}
}

View File

@ -14,6 +14,7 @@ type Alias struct {
Hostname string `json:"hostname,omitempty"`
Location *data.Location `json:"location,omitempty"`
Wireless *data.Wireless `json:"wireless,omitempty"`
Owner string `json:"owner,omitempty"`
}
// Nodes struct: cache DB of Node's structs

View File

@ -44,10 +44,14 @@ func NewStatsDb() *StatsDb {
return db
}
func (c *StatsDb) Add(stats *data.Statistics) {
func (c *StatsDb) Add(stats *data.Statistics, node *data.NodeInfo) {
tags := map[string]string{
"nodeid": stats.NodeId,
}
// Maybe a If
if owner := node.Owner; owner != nil {
tags["owner"] = owner.Contact
}
fields := map[string]interface{}{
"load": stats.LoadAverage,
"idletime": int64(stats.Idletime),