first implementation of neighbours count
This commit is contained in:
parent
d855248f6a
commit
2380c7de9a
@ -19,7 +19,7 @@ type Statistics struct {
|
|||||||
Total uint32 `json:"total"`
|
Total uint32 `json:"total"`
|
||||||
Running uint32 `json:"running"`
|
Running uint32 `json:"running"`
|
||||||
} `json:"processes,omitempty"`
|
} `json:"processes,omitempty"`
|
||||||
MeshVpn *MeshVPN `json:"mesh_vpn,omitempty"`
|
MeshVPN *MeshVPN `json:"mesh_vpn,omitempty"`
|
||||||
Traffic struct {
|
Traffic struct {
|
||||||
Tx *Traffic `json:"tx"`
|
Tx *Traffic `json:"tx"`
|
||||||
Rx *Traffic `json:"rx"`
|
Rx *Traffic `json:"rx"`
|
||||||
|
@ -51,7 +51,7 @@ type Statistics struct {
|
|||||||
Total uint32 `json:"total"`
|
Total uint32 `json:"total"`
|
||||||
Running uint32 `json:"running"`
|
Running uint32 `json:"running"`
|
||||||
} `json:"processes,omitempty"`
|
} `json:"processes,omitempty"`
|
||||||
MeshVpn *data.MeshVPN `json:"mesh_vpn,omitempty"`
|
MeshVPN *data.MeshVPN `json:"mesh_vpn,omitempty"`
|
||||||
Traffic struct {
|
Traffic struct {
|
||||||
Tx *data.Traffic `json:"tx"`
|
Tx *data.Traffic `json:"tx"`
|
||||||
Rx *data.Traffic `json:"rx"`
|
Rx *data.Traffic `json:"rx"`
|
||||||
@ -81,7 +81,7 @@ func NewStatistics(stats *data.Statistics) *Statistics {
|
|||||||
Uptime: stats.Uptime,
|
Uptime: stats.Uptime,
|
||||||
Idletime: stats.Idletime,
|
Idletime: stats.Idletime,
|
||||||
Processes: stats.Processes,
|
Processes: stats.Processes,
|
||||||
MeshVpn: stats.MeshVpn,
|
MeshVPN: stats.MeshVPN,
|
||||||
Traffic: stats.Traffic,
|
Traffic: stats.Traffic,
|
||||||
Clients: total,
|
Clients: total,
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ type Node struct {
|
|||||||
Neighbours *data.Neighbours `json:"-"`
|
Neighbours *data.Neighbours `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns tags and fields for InfluxDB
|
// ToInflux Returns tags and fields for InfluxDB
|
||||||
func (node *Node) ToInflux() (tags imodels.Tags, fields imodels.Fields) {
|
func (node *Node) ToInflux() (tags imodels.Tags, fields imodels.Fields) {
|
||||||
stats := node.Statistics
|
stats := node.Statistics
|
||||||
|
|
||||||
@ -51,6 +51,35 @@ func (node *Node) ToInflux() (tags imodels.Tags, fields imodels.Fields) {
|
|||||||
tags.SetString("hostname", nodeinfo.Hostname)
|
tags.SetString("hostname", nodeinfo.Hostname)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if neighbours := node.Neighbours; neighbours != nil {
|
||||||
|
// VPN Neighbours are Neighbours but includet in one protocol
|
||||||
|
vpn := 0
|
||||||
|
if meshvpn := stats.MeshVPN; meshvpn != nil {
|
||||||
|
for _, group := range meshvpn.Groups {
|
||||||
|
for _, link := range group.Peers {
|
||||||
|
if link.Established > 1 {
|
||||||
|
vpn++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fields["neighbours.vpn"] = vpn
|
||||||
|
|
||||||
|
// protocol: Batman Advance
|
||||||
|
batadv := 0
|
||||||
|
for _, batadvNeighbours := range neighbours.Batadv {
|
||||||
|
batadv += len(batadvNeighbours.Neighbours)
|
||||||
|
}
|
||||||
|
fields["neighbours.batadv"] = batadv
|
||||||
|
|
||||||
|
// protocol: LLDP
|
||||||
|
lldp := len(neighbours.LLDP)
|
||||||
|
fields["neighbours.lldp"] = lldp
|
||||||
|
|
||||||
|
// total is the sum of all protocols
|
||||||
|
fields["neighbours.total"] = batadv + lldp
|
||||||
|
}
|
||||||
|
|
||||||
if t := stats.Traffic.Rx; t != nil {
|
if t := stats.Traffic.Rx; t != nil {
|
||||||
fields["traffic.rx.bytes"] = int64(t.Bytes)
|
fields["traffic.rx.bytes"] = int64(t.Bytes)
|
||||||
fields["traffic.rx.packets"] = t.Packets
|
fields["traffic.rx.packets"] = t.Packets
|
||||||
|
84
models/node_test.go
Normal file
84
models/node_test.go
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/FreifunkBremen/respond-collector/data"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestToInflux(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
node := Node{
|
||||||
|
Statistics: &data.Statistics{
|
||||||
|
NodeID: "foobar",
|
||||||
|
LoadAverage: 0.5,
|
||||||
|
Wireless: data.WirelessStatistics{
|
||||||
|
&data.WirelessAirtime{Frequency: 5500},
|
||||||
|
},
|
||||||
|
Traffic: struct {
|
||||||
|
Tx *data.Traffic `json:"tx"`
|
||||||
|
Rx *data.Traffic `json:"rx"`
|
||||||
|
Forward *data.Traffic `json:"forward"`
|
||||||
|
MgmtTx *data.Traffic `json:"mgmt_tx"`
|
||||||
|
MgmtRx *data.Traffic `json:"mgmt_rx"`
|
||||||
|
}{
|
||||||
|
Tx: &data.Traffic{Dropped: 1321},
|
||||||
|
Rx: &data.Traffic{Bytes: 1213},
|
||||||
|
Forward: &data.Traffic{Bytes: 1322},
|
||||||
|
MgmtTx: &data.Traffic{Packets: 2327},
|
||||||
|
MgmtRx: &data.Traffic{Bytes: 2331},
|
||||||
|
},
|
||||||
|
MeshVPN: &data.MeshVPN{
|
||||||
|
Groups: map[string]*data.MeshVPNPeerGroup{
|
||||||
|
"ffhb": &data.MeshVPNPeerGroup{
|
||||||
|
Peers: map[string]*data.MeshVPNPeerLink{
|
||||||
|
"vpn01": &data.MeshVPNPeerLink{Established: 3},
|
||||||
|
"vpn02": &data.MeshVPNPeerLink{},
|
||||||
|
"vpn03": &data.MeshVPNPeerLink{Established: 0},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Nodeinfo: &data.NodeInfo{
|
||||||
|
Owner: &data.Owner{
|
||||||
|
Contact: "nobody",
|
||||||
|
},
|
||||||
|
Wireless: &data.Wireless{
|
||||||
|
TxPower24: 3,
|
||||||
|
Channel24: 4,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Neighbours: &data.Neighbours{
|
||||||
|
Batadv: map[string]data.BatadvNeighbours{
|
||||||
|
"a-interface": data.BatadvNeighbours{
|
||||||
|
Neighbours: map[string]data.BatmanLink{
|
||||||
|
"b-neigbourinterface": data.BatmanLink{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
tags, fields := node.ToInflux()
|
||||||
|
|
||||||
|
assert.Equal("foobar", tags.GetString("nodeid"))
|
||||||
|
assert.Equal("nobody", tags.GetString("owner"))
|
||||||
|
assert.Equal(0.5, fields["load"])
|
||||||
|
assert.Equal(0, fields["neighbours.lldp"])
|
||||||
|
assert.Equal(1, fields["neighbours.batadv"])
|
||||||
|
assert.Equal(1, fields["neighbours.vpn"])
|
||||||
|
assert.Equal(1, fields["neighbours.total"])
|
||||||
|
|
||||||
|
assert.Equal(uint32(3), fields["wireless.txpower24"])
|
||||||
|
assert.Equal(uint32(5500), fields["airtime11a.frequency"])
|
||||||
|
assert.Equal("", tags.GetString("frequency5500"))
|
||||||
|
|
||||||
|
assert.Equal(int64(1213), fields["traffic.rx.bytes"])
|
||||||
|
assert.Equal(float64(1321), fields["traffic.tx.dropped"])
|
||||||
|
assert.Equal(int64(1322), fields["traffic.forward.bytes"])
|
||||||
|
assert.Equal(int64(2331), fields["traffic.mgmt_rx.bytes"])
|
||||||
|
assert.Equal(float64(2327), fields["traffic.mgmt_tx.packets"])
|
||||||
|
}
|
@ -73,26 +73,3 @@ func TestUpdateNodes(t *testing.T) {
|
|||||||
|
|
||||||
assert.Equal(1, len(nodes.List))
|
assert.Equal(1, len(nodes.List))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestToInflux(t *testing.T) {
|
|
||||||
assert := assert.New(t)
|
|
||||||
|
|
||||||
node := Node{
|
|
||||||
Statistics: &data.Statistics{
|
|
||||||
NodeID: "foobar",
|
|
||||||
LoadAverage: 0.5,
|
|
||||||
},
|
|
||||||
Nodeinfo: &data.NodeInfo{
|
|
||||||
Owner: &data.Owner{
|
|
||||||
Contact: "nobody",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Neighbours: &data.Neighbours{},
|
|
||||||
}
|
|
||||||
|
|
||||||
tags, fields := node.ToInflux()
|
|
||||||
|
|
||||||
assert.Equal("foobar", tags.GetString("nodeid"))
|
|
||||||
assert.Equal("nobody", tags.GetString("owner"))
|
|
||||||
assert.Equal(0.5, fields["load"])
|
|
||||||
}
|
|
||||||
|
@ -23,6 +23,11 @@ func TestGlobalStats(t *testing.T) {
|
|||||||
// check firmwares
|
// check firmwares
|
||||||
assert.EqualValues(1, len(stats.Firmwares))
|
assert.EqualValues(1, len(stats.Firmwares))
|
||||||
assert.EqualValues(1, stats.Firmwares["2016.1.6+entenhausen1"])
|
assert.EqualValues(1, stats.Firmwares["2016.1.6+entenhausen1"])
|
||||||
|
|
||||||
|
fields := stats.Fields()
|
||||||
|
|
||||||
|
// check fields
|
||||||
|
assert.EqualValues(3, fields["nodes"])
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNodesV1(t *testing.T) {
|
func TestNodesV1(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user