[influxdb] site_code tag to global, firmware and model
This commit is contained in:
parent
5d6f046e39
commit
1d7d56131d
|
@ -10,13 +10,13 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGlobalStats(t *testing.T) {
|
func TestGlobalStats(t *testing.T) {
|
||||||
stats := runtime.NewGlobalStats(createTestNodes())
|
stats := runtime.NewGlobalStats(createTestNodes(), "ffhb01")
|
||||||
|
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
fields := GlobalStatsFields(stats)
|
fields := GlobalStatsFields(stats)
|
||||||
|
|
||||||
// check fields
|
// check fields
|
||||||
assert.EqualValues(3, fields["nodes"])
|
assert.EqualValues(2, fields["nodes"])
|
||||||
}
|
}
|
||||||
|
|
||||||
func createTestNodes() *runtime.Nodes {
|
func createTestNodes() *runtime.Nodes {
|
||||||
|
@ -32,6 +32,9 @@ func createTestNodes() *runtime.Nodes {
|
||||||
Hardware: data.Hardware{
|
Hardware: data.Hardware{
|
||||||
Model: "TP-Link 841",
|
Model: "TP-Link 841",
|
||||||
},
|
},
|
||||||
|
System: data.System{
|
||||||
|
SiteCode: "ffhb01",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
nodeData.NodeInfo.Software.Firmware.Release = "2016.1.6+entenhausen1"
|
nodeData.NodeInfo.Software.Firmware.Release = "2016.1.6+entenhausen1"
|
||||||
|
@ -47,6 +50,9 @@ func createTestNodes() *runtime.Nodes {
|
||||||
Hardware: data.Hardware{
|
Hardware: data.Hardware{
|
||||||
Model: "TP-Link 841",
|
Model: "TP-Link 841",
|
||||||
},
|
},
|
||||||
|
System: data.System{
|
||||||
|
SiteCode: "ffhb01",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ type Collector struct {
|
||||||
iface string
|
iface string
|
||||||
db database.Connection
|
db database.Connection
|
||||||
nodes *runtime.Nodes
|
nodes *runtime.Nodes
|
||||||
|
sites []string
|
||||||
interval time.Duration // Interval for multicast packets
|
interval time.Duration // Interval for multicast packets
|
||||||
stop chan interface{}
|
stop chan interface{}
|
||||||
}
|
}
|
||||||
|
@ -207,6 +208,11 @@ func (coll *Collector) saveResponse(addr net.UDPAddr, res *data.ResponseData) {
|
||||||
// Process the data and update IP address
|
// Process the data and update IP address
|
||||||
node := coll.nodes.Update(nodeID, res)
|
node := coll.nodes.Update(nodeID, res)
|
||||||
node.Address = addr.IP
|
node.Address = addr.IP
|
||||||
|
if nodeinfo := node.Nodeinfo; nodeinfo != nil {
|
||||||
|
if len(nodeinfo.System.SiteCode) > 0 {
|
||||||
|
coll.sites = append(coll.sites, nodeinfo.System.SiteCode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Store statistics in InfluxDB
|
// Store statistics in InfluxDB
|
||||||
if coll.db != nil && node.Statistics != nil {
|
if coll.db != nil && node.Statistics != nil {
|
||||||
|
@ -249,7 +255,8 @@ func (coll *Collector) globalStatsWorker() {
|
||||||
|
|
||||||
// saves global statistics
|
// saves global statistics
|
||||||
func (coll *Collector) saveGlobalStats() {
|
func (coll *Collector) saveGlobalStats() {
|
||||||
stats := runtime.NewGlobalStats(coll.nodes)
|
for _, site := range coll.sites {
|
||||||
|
stats := runtime.NewGlobalStats(coll.nodes, site)
|
||||||
coll.db.AddStatistics(stats, time.Now())
|
coll.db.AddStatistics(stats, time.Now())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,15 +17,16 @@ type GlobalStats struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
//NewGlobalStats returns global statistics for InfluxDB
|
//NewGlobalStats returns global statistics for InfluxDB
|
||||||
func NewGlobalStats(nodes *Nodes) (result *GlobalStats) {
|
func NewGlobalStats(nodes *Nodes, site string) (result *GlobalStats) {
|
||||||
result = &GlobalStats{
|
result = &GlobalStats{
|
||||||
Firmwares: make(CounterMap),
|
Firmwares: make(CounterMap),
|
||||||
Models: make(CounterMap),
|
Models: make(CounterMap),
|
||||||
}
|
}
|
||||||
|
|
||||||
nodes.Lock()
|
|
||||||
for _, node := range nodes.List {
|
for _, node := range nodes.List {
|
||||||
if node.Online {
|
if node.Online {
|
||||||
|
if info := node.Nodeinfo; info != nil {
|
||||||
|
if len(site) == 0 || info.System.SiteCode == site {
|
||||||
result.Nodes++
|
result.Nodes++
|
||||||
if stats := node.Statistics; stats != nil {
|
if stats := node.Statistics; stats != nil {
|
||||||
result.Clients += stats.Clients.Total
|
result.Clients += stats.Clients.Total
|
||||||
|
@ -36,13 +37,13 @@ func NewGlobalStats(nodes *Nodes) (result *GlobalStats) {
|
||||||
if node.Gateway {
|
if node.Gateway {
|
||||||
result.Gateways++
|
result.Gateways++
|
||||||
}
|
}
|
||||||
if info := node.Nodeinfo; info != nil {
|
|
||||||
result.Models.Increment(info.Hardware.Model)
|
result.Models.Increment(info.Hardware.Model)
|
||||||
result.Firmwares.Increment(info.Software.Firmware.Release)
|
result.Firmwares.Increment(info.Software.Firmware.Release)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nodes.Unlock()
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGlobalStats(t *testing.T) {
|
func TestGlobalStats(t *testing.T) {
|
||||||
stats := NewGlobalStats(createTestNodes())
|
stats := NewGlobalStats(createTestNodes(), "ffhb")
|
||||||
|
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
assert.EqualValues(1, stats.Gateways)
|
assert.EqualValues(1, stats.Gateways)
|
||||||
|
@ -39,6 +39,9 @@ func createTestNodes() *Nodes {
|
||||||
Hardware: data.Hardware{
|
Hardware: data.Hardware{
|
||||||
Model: "TP-Link 841",
|
Model: "TP-Link 841",
|
||||||
},
|
},
|
||||||
|
System: data.System{
|
||||||
|
SiteCode: "ffhb",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
nodeData.NodeInfo.Software.Firmware.Release = "2016.1.6+entenhausen1"
|
nodeData.NodeInfo.Software.Firmware.Release = "2016.1.6+entenhausen1"
|
||||||
|
@ -54,6 +57,9 @@ func createTestNodes() *Nodes {
|
||||||
Hardware: data.Hardware{
|
Hardware: data.Hardware{
|
||||||
Model: "TP-Link 841",
|
Model: "TP-Link 841",
|
||||||
},
|
},
|
||||||
|
System: data.System{
|
||||||
|
SiteCode: "ffhb",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -63,6 +69,9 @@ func createTestNodes() *Nodes {
|
||||||
Hardware: data.Hardware{
|
Hardware: data.Hardware{
|
||||||
Model: "Xeon Multi-Core",
|
Model: "Xeon Multi-Core",
|
||||||
},
|
},
|
||||||
|
System: data.System{
|
||||||
|
SiteCode: "ffhb",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue