[TASK] improve neighbours stats (+ babel support)

This commit is contained in:
Martin/Geno 2019-05-28 19:27:48 +02:00
parent 6e745bf78f
commit 99eb11f2ef
No known key found for this signature in database
GPG Key ID: 9D7D3C6BFF600C6A
3 changed files with 78 additions and 42 deletions

View File

@ -30,25 +30,36 @@ func (c *Connection) InsertNode(node *runtime.Node) {
fields = append(fields, graphigo.Metric{Name: node_prefix + "." + name, Value: value}) fields = append(fields, graphigo.Metric{Name: node_prefix + "." + name, Value: value})
} }
vpnInterfaces := make(map[string]bool)
for _, mIface := range nodeinfo.Network.Mesh {
for _, tunnel := range mIface.Interfaces.Tunnel {
vpnInterfaces[tunnel] = true
}
}
if neighbours := node.Neighbours; neighbours != nil { if neighbours := node.Neighbours; neighbours != nil {
vpn := 0 vpn := 0
if meshvpn := stats.MeshVPN; meshvpn != nil {
for _, group := range meshvpn.Groups {
for _, link := range group.Peers {
if link != nil && link.Established > 1 {
vpn++
}
}
}
}
addField("neighbours.vpn", vpn)
// protocol: Batman Advance // protocol: Batman Advance
batadv := 0 batadv := 0
for _, batadvNeighbours := range neighbours.Batadv { for mac, batadvNeighbours := range neighbours.Batadv {
batadv += len(batadvNeighbours.Neighbours) batadv += len(batadvNeighbours.Neighbours)
if _, ok := vpnInterfaces[mac]; ok {
vpn += len(batadvNeighbours.Neighbours)
}
} }
addField("neighbours.batadv", batadv) addField("neighbours.batadv", batadv)
// protocol: Babel
babel := 0
for _, babelNeighbours := range neighbours.Babel {
babel += len(babelNeighbours.Neighbours)
if _, ok := vpnInterfaces[babelNeighbours.LinkLocalAddress]; ok {
vpn += len(babelNeighbours.Neighbours)
}
}
addField("neighbours.babel", babel)
// protocol: LLDP // protocol: LLDP
lldp := 0 lldp := 0
for _, lldpNeighbours := range neighbours.LLDP { for _, lldpNeighbours := range neighbours.LLDP {
@ -56,8 +67,10 @@ func (c *Connection) InsertNode(node *runtime.Node) {
} }
addField("neighbours.lldp", lldp) addField("neighbours.lldp", lldp)
addField("neighbours.vpn", vpn)
// total is the sum of all protocols // total is the sum of all protocols
addField("neighbours.total", batadv+lldp) addField("neighbours.total", batadv+babel+lldp)
} }
if t := stats.Traffic.Rx; t != nil { if t := stats.Traffic.Rx; t != nil {

View File

@ -48,7 +48,15 @@ func (conn *Connection) InsertNode(node *runtime.Node) {
"memory.available": stats.Memory.Available, "memory.available": stats.Memory.Available,
} }
vpnInterfaces := make(map[string]bool)
if nodeinfo := node.Nodeinfo; nodeinfo != nil { if nodeinfo := node.Nodeinfo; nodeinfo != nil {
for _, mIface := range nodeinfo.Network.Mesh {
for _, tunnel := range mIface.Interfaces.Tunnel {
vpnInterfaces[tunnel] = true
}
}
tags.SetString("hostname", nodeinfo.Hostname) tags.SetString("hostname", nodeinfo.Hostname)
if nodeinfo.System.SiteCode != "" { if nodeinfo.System.SiteCode != "" {
tags.SetString("site", nodeinfo.System.SiteCode) tags.SetString("site", nodeinfo.System.SiteCode)
@ -75,28 +83,30 @@ func (conn *Connection) InsertNode(node *runtime.Node) {
} }
} }
if neighbours := node.Neighbours; neighbours != nil { if neighbours := node.Neighbours; neighbours != nil {
// VPN Neighbours are Neighbours but includet in one protocol // VPN Neighbours are Neighbours but includet in one protocol
vpn := 0 vpn := 0
if meshvpn := stats.MeshVPN; meshvpn != nil {
for _, group := range meshvpn.Groups {
for _, link := range group.Peers {
if link != nil && link.Established > 1 {
vpn++
}
}
}
}
fields["neighbours.vpn"] = vpn
// protocol: Batman Advance // protocol: Batman Advance
batadv := 0 batadv := 0
for _, batadvNeighbours := range neighbours.Batadv { for mac, batadvNeighbours := range neighbours.Batadv {
batadv += len(batadvNeighbours.Neighbours) batadv += len(batadvNeighbours.Neighbours)
if _, ok := vpnInterfaces[mac]; ok {
vpn += len(batadvNeighbours.Neighbours)
}
} }
fields["neighbours.batadv"] = batadv fields["neighbours.batadv"] = batadv
// protocol: Babel
babel := 0
for _, babelNeighbours := range neighbours.Babel {
babel += len(babelNeighbours.Neighbours)
if _, ok := vpnInterfaces[babelNeighbours.LinkLocalAddress]; ok {
vpn += len(babelNeighbours.Neighbours)
}
}
fields["neighbours.babel"] = babel
// protocol: LLDP // protocol: LLDP
lldp := 0 lldp := 0
for _, lldpNeighbours := range neighbours.LLDP { for _, lldpNeighbours := range neighbours.LLDP {
@ -104,8 +114,11 @@ func (conn *Connection) InsertNode(node *runtime.Node) {
} }
fields["neighbours.lldp"] = lldp fields["neighbours.lldp"] = lldp
// vpn wait for babel
fields["neighbours.vpn"] = vpn
// total is the sum of all protocols // total is the sum of all protocols
fields["neighbours.total"] = batadv + lldp fields["neighbours.total"] = batadv + babel + lldp
} }
if procstat := stats.ProcStats; procstat != nil { if procstat := stats.ProcStats; procstat != nil {
fields["stat.cpu.user"] = procstat.CPU.User fields["stat.cpu.user"] = procstat.CPU.User

View File

@ -39,18 +39,6 @@ func TestToInflux(t *testing.T) {
MgmtTx: &data.Traffic{Packets: 2327}, MgmtTx: &data.Traffic{Packets: 2327},
MgmtRx: &data.Traffic{Bytes: 2331}, MgmtRx: &data.Traffic{Bytes: 2331},
}, },
MeshVPN: &data.MeshVPN{
Groups: map[string]*data.MeshVPNPeerGroup{
"ffhb": {
Peers: map[string]*data.MeshVPNPeerLink{
"vpn01": {Established: 3},
"vpn02": {},
"trash": nil,
"vpn03": {Established: 0},
},
},
},
},
}, },
Nodeinfo: &data.Nodeinfo{ Nodeinfo: &data.Nodeinfo{
NodeID: "deadbeef", NodeID: "deadbeef",
@ -67,6 +55,17 @@ func TestToInflux(t *testing.T) {
}, },
Network: data.Network{ Network: data.Network{
Mac: "DEADMAC", Mac: "DEADMAC",
Mesh: map[string]*data.NetworkInterface{
"bat0": {
Interfaces: struct {
Wireless []string `json:"wireless,omitempty"`
Other []string `json:"other,omitempty"`
Tunnel []string `json:"tunnel,omitempty"`
}{
Tunnel: []string{"a-interface-mac", "fe80::1"},
},
},
},
}, },
Software: data.Software{ Software: data.Software{
Autoupdater: struct { Autoupdater: struct {
@ -81,7 +80,7 @@ func TestToInflux(t *testing.T) {
Neighbours: &data.Neighbours{ Neighbours: &data.Neighbours{
NodeID: "deadbeef", NodeID: "deadbeef",
Batadv: map[string]data.BatadvNeighbours{ Batadv: map[string]data.BatadvNeighbours{
"a-interface": { "a-interface-mac": {
Neighbours: map[string]data.BatmanLink{ Neighbours: map[string]data.BatmanLink{
"BAFF1E5": { "BAFF1E5": {
Tq: 204, Tq: 204,
@ -89,8 +88,18 @@ func TestToInflux(t *testing.T) {
}, },
}, },
}, },
Babel: map[string]data.BabelNeighbours{
"wg-01": {
LinkLocalAddress: "fe80::1",
Neighbours: map[string]data.BabelLink{
"fe80::2": {
Cost: 0,
},
},
},
},
LLDP: map[string]data.LLDPNeighbours{ LLDP: map[string]data.LLDPNeighbours{
"b-interface": {}, "b-interface-mac": {},
}, },
}, },
} }
@ -144,9 +153,10 @@ func TestToInflux(t *testing.T) {
assert.EqualValues("city", tags["domain"]) assert.EqualValues("city", tags["domain"])
assert.EqualValues(0.5, fields["load"]) assert.EqualValues(0.5, fields["load"])
assert.EqualValues(0, fields["neighbours.lldp"]) assert.EqualValues(0, fields["neighbours.lldp"])
assert.EqualValues(1, fields["neighbours.babel"])
assert.EqualValues(1, fields["neighbours.batadv"]) assert.EqualValues(1, fields["neighbours.batadv"])
assert.EqualValues(1, fields["neighbours.vpn"]) assert.EqualValues(2, fields["neighbours.vpn"])
assert.EqualValues(1, fields["neighbours.total"]) assert.EqualValues(2, fields["neighbours.total"])
assert.EqualValues(uint32(3), fields["wireless.txpower24"]) assert.EqualValues(uint32(3), fields["wireless.txpower24"])
assert.EqualValues(uint32(5500), fields["airtime11a.frequency"]) assert.EqualValues(uint32(5500), fields["airtime11a.frequency"])
@ -165,7 +175,7 @@ func TestToInflux(t *testing.T) {
assert.EqualValues("link", nPoint.Name()) assert.EqualValues("link", nPoint.Name())
assert.EqualValues(map[string]string{ assert.EqualValues(map[string]string{
"source.id": "deadbeef", "source.id": "deadbeef",
"source.addr": "a-interface", "source.addr": "a-interface-mac",
"target.id": "foobar", "target.id": "foobar",
"target.addr": "BAFF1E5", "target.addr": "BAFF1E5",
}, tags) }, tags)