diff --git a/database/influxdb/database.go b/database/influxdb/database.go index 6239916..b8e99d1 100644 --- a/database/influxdb/database.go +++ b/database/influxdb/database.go @@ -12,13 +12,14 @@ import ( ) const ( - MeasurementLink = "link" // Measurement for per-link statistics - MeasurementNode = "node" // Measurement for per-node statistics - MeasurementGlobal = "global" // Measurement for summarized global statistics - CounterMeasurementFirmware = "firmware" // Measurement for firmware statistics - CounterMeasurementModel = "model" // Measurement for model statistics - batchMaxSize = 500 - batchTimeout = 5 * time.Second + MeasurementLink = "link" // Measurement for per-link statistics + MeasurementNode = "node" // Measurement for per-node statistics + 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 ) type Connection struct { diff --git a/database/influxdb/global.go b/database/influxdb/global.go index 26d27bb..0a302d5 100644 --- a/database/influxdb/global.go +++ b/database/influxdb/global.go @@ -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 diff --git a/database/influxdb/global_test.go b/database/influxdb/global_test.go index f1ced75..5f43eb5 100644 --- a/database/influxdb/global_test.go +++ b/database/influxdb/global_test.go @@ -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{ diff --git a/database/influxdb/node.go b/database/influxdb/node.go index d00f558..1395b39 100644 --- a/database/influxdb/node.go +++ b/database/influxdb/node.go @@ -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) + } } diff --git a/database/influxdb/node_test.go b/database/influxdb/node_test.go index 6bda061..dc6194b 100644 --- a/database/influxdb/node_test.go +++ b/database/influxdb/node_test.go @@ -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 diff --git a/runtime/stats.go b/runtime/stats.go index a477303..29e6562 100644 --- a/runtime/stats.go +++ b/runtime/stats.go @@ -1,5 +1,7 @@ package runtime +const DISABLED_AUTOUPDATER = "disabled" + // CounterMap to manage multiple values type CounterMap map[string]uint32 @@ -12,15 +14,17 @@ type GlobalStats struct { Gateways uint32 Nodes uint32 - Firmwares CounterMap - Models CounterMap + Firmwares CounterMap + Models CounterMap + Autoupdater CounterMap } //NewGlobalStats returns global statistics for InfluxDB func NewGlobalStats(nodes *Nodes) (result *GlobalStats) { result = &GlobalStats{ - Firmwares: make(CounterMap), - Models: make(CounterMap), + 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) + } } } } diff --git a/runtime/stats_test.go b/runtime/stats_test.go index 0a4ace4..c2bbecd 100644 --- a/runtime/stats_test.go +++ b/runtime/stats_test.go @@ -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", + }, + }, }, })