[TASK] add autoupdater to influxdb database (#93)
This commit is contained in:
parent
037ff80193
commit
0d8fddbcb7
|
@ -17,6 +17,7 @@ const (
|
|||
MeasurementGlobal = "global" // Measurement for summarized global statistics
|
||||
CounterMeasurementFirmware = "firmware" // Measurement for firmware statistics
|
||||
CounterMeasurementModel = "model" // Measurement for model statistics
|
||||
CounterMeasurementAutoupdater = "autoupdater" // Measurement for autoupdater
|
||||
batchMaxSize = 500
|
||||
batchTimeout = 5 * time.Second
|
||||
)
|
||||
|
|
|
@ -12,6 +12,7 @@ func (conn *Connection) InsertGlobals(stats *runtime.GlobalStats, time time.Time
|
|||
conn.addPoint(MeasurementGlobal, nil, GlobalStatsFields(stats), time)
|
||||
conn.addCounterMap(CounterMeasurementModel, stats.Models, time)
|
||||
conn.addCounterMap(CounterMeasurementFirmware, stats.Firmwares, time)
|
||||
conn.addCounterMap(CounterMeasurementAutoupdater, stats.Autoupdater, time)
|
||||
}
|
||||
|
||||
// GlobalStatsFields returns fields for InfluxDB
|
||||
|
|
|
@ -37,6 +37,8 @@ func createTestNodes() *runtime.Nodes {
|
|||
},
|
||||
}
|
||||
nodeData.Nodeinfo.Software.Firmware.Release = "2016.1.6+entenhausen1"
|
||||
nodeData.Nodeinfo.Software.Autoupdater.Enabled = true
|
||||
nodeData.Nodeinfo.Software.Autoupdater.Branch = "stable"
|
||||
nodes.AddNode(nodeData)
|
||||
|
||||
nodes.AddNode(&runtime.Node{
|
||||
|
|
|
@ -60,6 +60,11 @@ func (conn *Connection) InsertNode(node *runtime.Node) {
|
|||
tags.SetString("model", nodeinfo.Hardware.Model)
|
||||
tags.SetString("firmware_base", nodeinfo.Software.Firmware.Base)
|
||||
tags.SetString("firmware_release", nodeinfo.Software.Firmware.Release)
|
||||
if nodeinfo.Software.Autoupdater.Enabled {
|
||||
tags.SetString("autoupdater", nodeinfo.Software.Autoupdater.Branch)
|
||||
} else {
|
||||
tags.SetString("autoupdater", runtime.DISABLED_AUTOUPDATER)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -58,6 +58,15 @@ func TestToInflux(t *testing.T) {
|
|||
Network: data.Network{
|
||||
Mac: "DEADMAC",
|
||||
},
|
||||
Software: data.Software{
|
||||
Autoupdater: struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
Branch string `json:"branch,omitempty"`
|
||||
}{
|
||||
Enabled: true,
|
||||
Branch: "testing",
|
||||
},
|
||||
},
|
||||
},
|
||||
Neighbours: &data.Neighbours{
|
||||
NodeID: "deadbeef",
|
||||
|
@ -80,15 +89,36 @@ func TestToInflux(t *testing.T) {
|
|||
Network: data.Network{
|
||||
Mac: "BAFF1E5",
|
||||
},
|
||||
Software: data.Software{
|
||||
Autoupdater: struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
Branch string `json:"branch,omitempty"`
|
||||
}{
|
||||
Enabled: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
Statistics: &data.Statistics{
|
||||
NodeID: "foobar",
|
||||
},
|
||||
}
|
||||
|
||||
// do not add a empty statistics of a node
|
||||
droppednode := &runtime.Node{
|
||||
Nodeinfo: &data.NodeInfo{
|
||||
NodeID: "notfound",
|
||||
Network: data.Network{
|
||||
Mac: "instats",
|
||||
},
|
||||
},
|
||||
Statistics: &data.Statistics{},
|
||||
}
|
||||
|
||||
points := testPoints(node, neigbour)
|
||||
points := testPoints(node, neigbour, droppednode)
|
||||
var fields map[string]interface{}
|
||||
var tags map[string]string
|
||||
|
||||
assert.Len(points, 2)
|
||||
assert.Len(points, 3)
|
||||
|
||||
// first point contains the neighbour
|
||||
sPoint := points[0]
|
||||
|
@ -97,6 +127,7 @@ func TestToInflux(t *testing.T) {
|
|||
|
||||
assert.EqualValues("deadbeef", tags["nodeid"])
|
||||
assert.EqualValues("nobody", tags["owner"])
|
||||
assert.EqualValues("testing", tags["autoupdater"])
|
||||
assert.EqualValues(0.5, fields["load"])
|
||||
assert.EqualValues(0, fields["neighbours.lldp"])
|
||||
assert.EqualValues(1, fields["neighbours.batadv"])
|
||||
|
@ -113,7 +144,7 @@ func TestToInflux(t *testing.T) {
|
|||
assert.EqualValues(int64(2331), fields["traffic.mgmt_rx.bytes"])
|
||||
assert.EqualValues(float64(2327), fields["traffic.mgmt_tx.packets"])
|
||||
|
||||
// second point contains the neighbour
|
||||
// second point contains the link
|
||||
nPoint := points[1]
|
||||
tags = nPoint.Tags()
|
||||
fields, _ = nPoint.Fields()
|
||||
|
@ -125,6 +156,11 @@ func TestToInflux(t *testing.T) {
|
|||
"target.mac": "BAFF1E5",
|
||||
}, tags)
|
||||
assert.EqualValues(80, fields["tq"])
|
||||
|
||||
// third point contains the neighbour
|
||||
nPoint = points[2]
|
||||
tags = nPoint.Tags()
|
||||
assert.EqualValues("disabled", tags["autoupdater"])
|
||||
}
|
||||
|
||||
// Processes data and returns the InfluxDB points
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package runtime
|
||||
|
||||
const DISABLED_AUTOUPDATER = "disabled"
|
||||
|
||||
// CounterMap to manage multiple values
|
||||
type CounterMap map[string]uint32
|
||||
|
||||
|
@ -14,6 +16,7 @@ type GlobalStats struct {
|
|||
|
||||
Firmwares CounterMap
|
||||
Models CounterMap
|
||||
Autoupdater CounterMap
|
||||
}
|
||||
|
||||
//NewGlobalStats returns global statistics for InfluxDB
|
||||
|
@ -21,6 +24,7 @@ func NewGlobalStats(nodes *Nodes) (result *GlobalStats) {
|
|||
result = &GlobalStats{
|
||||
Firmwares: make(CounterMap),
|
||||
Models: make(CounterMap),
|
||||
Autoupdater: make(CounterMap),
|
||||
}
|
||||
|
||||
nodes.RLock()
|
||||
|
@ -39,6 +43,11 @@ func NewGlobalStats(nodes *Nodes) (result *GlobalStats) {
|
|||
if info := node.Nodeinfo; info != nil {
|
||||
result.Models.Increment(info.Hardware.Model)
|
||||
result.Firmwares.Increment(info.Software.Firmware.Release)
|
||||
if info.Software.Autoupdater.Enabled {
|
||||
result.Autoupdater.Increment(info.Software.Autoupdater.Branch)
|
||||
} else {
|
||||
result.Autoupdater.Increment(DISABLED_AUTOUPDATER)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,10 @@ func TestGlobalStats(t *testing.T) {
|
|||
// check firmwares
|
||||
assert.Len(stats.Firmwares, 1)
|
||||
assert.EqualValues(1, stats.Firmwares["2016.1.6+entenhausen1"])
|
||||
|
||||
// check autoupdater
|
||||
assert.Len(stats.Autoupdater, 2)
|
||||
assert.EqualValues(1, stats.Autoupdater["stable"])
|
||||
}
|
||||
|
||||
func createTestNodes() *Nodes {
|
||||
|
@ -58,6 +62,15 @@ func createTestNodes() *Nodes {
|
|||
Hardware: data.Hardware{
|
||||
Model: "TP-Link 841",
|
||||
},
|
||||
Software: data.Software{
|
||||
Autoupdater: struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
Branch string `json:"branch,omitempty"`
|
||||
}{
|
||||
Enabled: true,
|
||||
Branch: "stable",
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue