From c13185fd51de8fa8656f83b71ae67d832ff8e9c6 Mon Sep 17 00:00:00 2001 From: Martin Geno Date: Sat, 9 Jul 2016 02:33:34 +0200 Subject: [PATCH] add owner (as tag) --- main.go | 6 +++++- models/aliases.go | 1 + stats_db.go | 6 +++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index a494737..2ef539d 100644 --- a/main.go +++ b/main.go @@ -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) + } } } diff --git a/models/aliases.go b/models/aliases.go index c506738..21aa4d9 100644 --- a/models/aliases.go +++ b/models/aliases.go @@ -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 diff --git a/stats_db.go b/stats_db.go index 5c4fcf0..80b17f8 100644 --- a/stats_db.go +++ b/stats_db.go @@ -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),