Skip to content

Commit

Permalink
add global measurment for autoupdater
Browse files Browse the repository at this point in the history
  • Loading branch information
genofire committed Nov 9, 2017
1 parent de92339 commit c3750ce
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 14 deletions.
15 changes: 8 additions & 7 deletions database/influxdb/database.go
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions database/influxdb/global.go
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions database/influxdb/global_test.go
Expand Up @@ -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{
Expand Down
2 changes: 2 additions & 0 deletions database/influxdb/node.go
Expand Up @@ -62,6 +62,8 @@ func (conn *Connection) InsertNode(node *runtime.Node) {
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)
}

}
Expand Down
32 changes: 29 additions & 3 deletions database/influxdb/node_test.go
Expand Up @@ -89,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]
Expand All @@ -123,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()
Expand All @@ -135,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
Expand Down
17 changes: 13 additions & 4 deletions runtime/stats.go
@@ -1,5 +1,7 @@
package runtime

const DISABLED_AUTOUPDATER = "disabled"

// CounterMap to manage multiple values
type CounterMap map[string]uint32

Expand All @@ -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()
Expand All @@ -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)
}
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions runtime/stats_test.go
Expand Up @@ -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 {
Expand Down Expand Up @@ -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",
},
},
},
})

Expand Down

0 comments on commit c3750ce

Please sign in to comment.