fix neighbour to influxdb

This commit is contained in:
Martin Geno 2017-01-21 04:24:04 +01:00
parent 2380c7de9a
commit 724cd8ba51
2 changed files with 7 additions and 2 deletions

View File

@ -57,7 +57,7 @@ func (node *Node) ToInflux() (tags imodels.Tags, fields imodels.Fields) {
if meshvpn := stats.MeshVPN; meshvpn != nil { if meshvpn := stats.MeshVPN; meshvpn != nil {
for _, group := range meshvpn.Groups { for _, group := range meshvpn.Groups {
for _, link := range group.Peers { for _, link := range group.Peers {
if link.Established > 1 { if link != nil && link.Established > 1 {
vpn++ vpn++
} }
} }
@ -73,7 +73,10 @@ func (node *Node) ToInflux() (tags imodels.Tags, fields imodels.Fields) {
fields["neighbours.batadv"] = batadv fields["neighbours.batadv"] = batadv
// protocol: LLDP // protocol: LLDP
lldp := len(neighbours.LLDP) lldp := 0
for _, lldpNeighbours := range neighbours.LLDP {
lldp += len(lldpNeighbours)
}
fields["neighbours.lldp"] = lldp fields["neighbours.lldp"] = lldp
// total is the sum of all protocols // total is the sum of all protocols

View File

@ -36,6 +36,7 @@ func TestToInflux(t *testing.T) {
Peers: map[string]*data.MeshVPNPeerLink{ Peers: map[string]*data.MeshVPNPeerLink{
"vpn01": &data.MeshVPNPeerLink{Established: 3}, "vpn01": &data.MeshVPNPeerLink{Established: 3},
"vpn02": &data.MeshVPNPeerLink{}, "vpn02": &data.MeshVPNPeerLink{},
"trash": nil,
"vpn03": &data.MeshVPNPeerLink{Established: 0}, "vpn03": &data.MeshVPNPeerLink{Established: 0},
}, },
}, },
@ -59,6 +60,7 @@ func TestToInflux(t *testing.T) {
}, },
}, },
}, },
LLDP: map[string]data.LLDPNeighbours{},
}, },
} }