feat(meshviewer): Add gateway tq and clients owe (#225)

Signed-off-by: Florian Maurer <f.maurer@outlook.de>
This commit is contained in:
Florian Maurer 2023-09-18 19:56:18 +02:00 committed by genofire
parent c3588c9e05
commit 22f67e2d4d
16 changed files with 52 additions and 41 deletions

View File

@ -19,7 +19,7 @@ type WifiLink struct {
// BatmanLink struct
type BatmanLink struct {
Lastseen float64 `json:"lastseen"`
Tq int `json:"tq"`
TQ int `json:"tq"`
}
// BabelLink struct

View File

@ -18,6 +18,7 @@ type Statistics struct {
GatewayIPv4 string `json:"gateway,omitempty"`
GatewayIPv6 string `json:"gateway6,omitempty"`
GatewayNexthop string `json:"gateway_nexthop,omitempty"`
GatewayTQ float64 `json:"gateway_tq,omitempty"`
Processes struct {
Total uint32 `json:"total"`
Running uint32 `json:"running"`
@ -63,9 +64,9 @@ type Clients struct {
Wifi uint32 `json:"wifi"`
Wifi24 uint32 `json:"wifi24"`
Wifi5 uint32 `json:"wifi5"`
Owe uint32 `json:"owe"`
Owe24 uint32 `json:"owe24"`
Owe5 uint32 `json:"owe5"`
OWE uint32 `json:"owe"`
OWE24 uint32 `json:"owe24"`
OWE5 uint32 `json:"owe5"`
Total uint32 `json:"total"`
}

View File

@ -20,9 +20,9 @@ func TestStatistics(t *testing.T) {
assert.Equal(uint32(35), obj.Clients.Wifi)
assert.Equal(uint32(30), obj.Clients.Wifi24)
assert.Equal(uint32(8), obj.Clients.Wifi5)
assert.Equal(uint32(10), obj.Clients.Owe)
assert.Equal(uint32(5), obj.Clients.Owe24)
assert.Equal(uint32(6), obj.Clients.Owe5)
assert.Equal(uint32(10), obj.Clients.OWE)
assert.Equal(uint32(5), obj.Clients.OWE24)
assert.Equal(uint32(6), obj.Clients.OWE5)
}
func testfile(name string, obj interface{}) {

View File

@ -41,9 +41,9 @@ func GlobalStatsFields(name string, stats *runtime.GlobalStats) []graphigo.Metri
{Name: name + ".clients.wifi", Value: stats.ClientsWifi},
{Name: name + ".clients.wifi24", Value: stats.ClientsWifi24},
{Name: name + ".clients.wifi5", Value: stats.ClientsWifi5},
{Name: name + ".clients.owe", Value: stats.ClientsOwe},
{Name: name + ".clients.owe24", Value: stats.ClientsOwe24},
{Name: name + ".clients.owe5", Value: stats.ClientsOwe5},
{Name: name + ".clients.owe", Value: stats.ClientsOWE},
{Name: name + ".clients.owe24", Value: stats.ClientsOWE24},
{Name: name + ".clients.owe5", Value: stats.ClientsOWE5},
}
}

View File

@ -112,9 +112,9 @@ func (c *Connection) InsertNode(node *runtime.Node) {
addField("clients.wifi", stats.Clients.Wifi)
addField("clients.wifi24", stats.Clients.Wifi24)
addField("clients.wifi5", stats.Clients.Wifi5)
addField("clients.owe", stats.Clients.Owe)
addField("clients.owe24", stats.Clients.Owe24)
addField("clients.owe5", stats.Clients.Owe5)
addField("clients.owe", stats.Clients.OWE)
addField("clients.owe24", stats.Clients.OWE24)
addField("clients.owe5", stats.Clients.OWE5)
addField("clients.total", stats.Clients.Total)
addField("memory.buffers", stats.Memory.Buffers)
addField("memory.cached", stats.Memory.Cached)

View File

@ -48,9 +48,9 @@ func GlobalStatsFields(stats *runtime.GlobalStats) map[string]interface{} {
"clients.wifi": stats.ClientsWifi,
"clients.wifi24": stats.ClientsWifi24,
"clients.wifi5": stats.ClientsWifi5,
"clients.owe": stats.ClientsOwe,
"clients.owe24": stats.ClientsOwe24,
"clients.owe5": stats.ClientsOwe5,
"clients.owe": stats.ClientsOWE,
"clients.owe24": stats.ClientsOWE24,
"clients.owe5": stats.ClientsOWE5,
}
}

View File

@ -43,9 +43,9 @@ func (conn *Connection) InsertNode(node *runtime.Node) {
"clients.wifi": stats.Clients.Wifi,
"clients.wifi24": stats.Clients.Wifi24,
"clients.wifi5": stats.Clients.Wifi5,
"clients.owe": stats.Clients.Owe,
"clients.owe24": stats.Clients.Owe24,
"clients.owe5": stats.Clients.Owe5,
"clients.owe": stats.Clients.OWE,
"clients.owe24": stats.Clients.OWE24,
"clients.owe5": stats.Clients.OWE5,
"clients.total": stats.Clients.Total,
"memory.buffers": stats.Memory.Buffers,
"memory.cached": stats.Memory.Cached,

View File

@ -83,7 +83,7 @@ func TestToInflux(t *testing.T) {
"a-interface-mac": {
Neighbours: map[string]data.BatmanLink{
"BAFF1E5": {
Tq: 204,
TQ: 204,
},
},
},

View File

@ -38,12 +38,12 @@ func TestTransform(t *testing.T) {
Batadv: map[string]data.BatadvNeighbours{
"node:a:mac:wifi": {
Neighbours: map[string]data.BatmanLink{
"node:b:mac:wifi": {Tq: 153},
"node:b:mac:wifi": {TQ: 153},
},
},
"node:a:mac:lan": {
Neighbours: map[string]data.BatmanLink{
"node:b:mac:lan": {Tq: 51},
"node:b:mac:lan": {TQ: 51},
},
},
},
@ -73,7 +73,7 @@ func TestTransform(t *testing.T) {
Batadv: map[string]data.BatadvNeighbours{
"node:c:mac:lan": {
Neighbours: map[string]data.BatmanLink{
"node:b:mac:lan": {Tq: 102},
"node:b:mac:lan": {TQ: 102},
},
},
},
@ -104,12 +104,12 @@ func TestTransform(t *testing.T) {
Batadv: map[string]data.BatadvNeighbours{
"node:b:mac:lan": {
Neighbours: map[string]data.BatmanLink{
"node:c:mac:lan": {Tq: 204},
"node:c:mac:lan": {TQ: 204},
},
},
"node:b:mac:wifi": {
Neighbours: map[string]data.BatmanLink{
"node:a:mac:wifi": {Tq: 204},
"node:a:mac:wifi": {TQ: 204},
},
},
},
@ -140,12 +140,12 @@ func TestTransform(t *testing.T) {
Batadv: map[string]data.BatadvNeighbours{
"node:d:mac:lan": {
Neighbours: map[string]data.BatmanLink{
"node:c:mac:lan": {Tq: 204},
"node:c:mac:lan": {TQ: 204},
},
},
"node:d:mac:wifi": {
Neighbours: map[string]data.BatmanLink{
"node:a:mac:wifi": {Tq: 204},
"node:a:mac:wifi": {TQ: 204},
},
},
},

View File

@ -22,6 +22,9 @@ type Node struct {
ClientsWifi24 uint32 `json:"clients_wifi24"`
ClientsWifi5 uint32 `json:"clients_wifi5"`
ClientsOthers uint32 `json:"clients_other"`
ClientsOWE uint32 `json:"clients_owe"`
ClientsOWE24 uint32 `json:"clients_owe24"`
ClientsOWE5 uint32 `json:"clients_owe5"`
RootFSUsage float64 `json:"rootfs_usage"`
LoadAverage float64 `json:"loadavg"`
MemoryUsage *float64 `json:"memory_usage,omitempty"`
@ -29,6 +32,7 @@ type Node struct {
GatewayNexthop string `json:"gateway_nexthop,omitempty"`
GatewayIPv4 string `json:"gateway,omitempty"`
GatewayIPv6 string `json:"gateway6,omitempty"`
GatewayTQ float64 `json:"gateway_tq,omitempty"`
NodeID string `json:"node_id"`
MAC string `json:"mac"`
Addresses []string `json:"addresses"`
@ -117,6 +121,9 @@ func NewNode(nodes *runtime.Nodes, n *runtime.Node) *Node {
node.Clients = statistic.Clients.Total
node.ClientsWifi24 = statistic.Clients.Wifi24
node.ClientsWifi5 = statistic.Clients.Wifi5
node.ClientsOWE = statistic.Clients.OWE
node.ClientsOWE24 = statistic.Clients.OWE24
node.ClientsOWE5 = statistic.Clients.OWE5
clientsWifi := node.ClientsWifi24 + node.ClientsWifi5
if node.Clients == 0 {

View File

@ -97,7 +97,7 @@ func (builder *graphBuilder) readNodes(nodes map[string]*runtime.Node) {
for targetAddress, link := range batadvNeighbours.Neighbours {
if targetID, found := builder.macToID[targetAddress]; found {
_, vpn := vpnInterface[sourceMAC]
builder.addLink(targetID, sourceID, link.Tq, vpn)
builder.addLink(targetID, sourceID, link.TQ, vpn)
}
}
}
@ -159,7 +159,7 @@ func (builder *graphBuilder) extract() ([]*GraphNode, []*GraphLink) {
return cache.Nodes, links
}
func (builder *graphBuilder) addLink(targetID string, sourceID string, linkTq int, vpn bool) {
func (builder *graphBuilder) addLink(targetID string, sourceID string, linkTQ int, vpn bool) {
// Sort IDs to generate the key
var key string
if strings.Compare(sourceID, targetID) > 0 {
@ -169,8 +169,8 @@ func (builder *graphBuilder) addLink(targetID string, sourceID string, linkTq in
}
var tq float32
if linkTq > 0 {
tq = float32(1.0 / (float32(linkTq) / 255.0))
if linkTQ > 0 {
tq = float32(1.0 / (float32(linkTQ) / 255.0))
}
if link, ok := builder.links[key]; !ok {

View File

@ -30,8 +30,10 @@ type Statistics struct {
MemoryUsage *float64 `json:"memory_usage,omitempty"`
Uptime float64 `json:"uptime,omitempty"`
Idletime float64 `json:"idletime,omitempty"`
GatewayNexthop string `json:"gateway_nexthop,omitempty"`
GatewayIPv4 string `json:"gateway,omitempty"`
GatewayIPv6 string `json:"gateway6,omitempty"`
GatewayTQ float64 `json:"gateway_tq,omitempty"`
Processes struct {
Total uint32 `json:"total"`
Running uint32 `json:"running"`
@ -52,6 +54,7 @@ func NewStatistics(stats *data.Statistics, isOnline bool) *Statistics {
NodeID: stats.NodeID,
GatewayIPv4: stats.GatewayIPv4,
GatewayIPv6: stats.GatewayIPv6,
GatewayTQ: stats.GatewayTQ,
RootFsUsage: stats.RootFsUsage,
LoadAverage: stats.LoadAverage,
Uptime: stats.Uptime,

View File

@ -47,12 +47,12 @@ func TestOutput(t *testing.T) {
Batadv: map[string]data.BatadvNeighbours{
"node:a:mac:wifi": {
Neighbours: map[string]data.BatmanLink{
"node:b:mac:wifi": {Tq: 153},
"node:b:mac:wifi": {TQ: 153},
},
},
"node:a:mac:lan": {
Neighbours: map[string]data.BatmanLink{
"node:b:mac:lan": {Tq: 51},
"node:b:mac:lan": {TQ: 51},
},
},
},

View File

@ -124,7 +124,7 @@ func (nodes *Nodes) NodeLinks(node *Node) (result []Link) {
SourceAddress: sourceMAC,
TargetID: neighbourID,
TargetAddress: neighbourMAC,
TQ: float32(link.Tq) / 255.0,
TQ: float32(link.TQ) / 255.0,
}
if neighbour.Nodeinfo != nil {

View File

@ -214,7 +214,7 @@ func TestLinksNodes(t *testing.T) {
"f4:f2:6d:d7:a3:0b": {
Neighbours: map[string]data.BatmanLink{
"f4:f2:6d:d7:a3:0a": {
Tq: 204, Lastseen: 0.42,
TQ: 204, Lastseen: 0.42,
},
},
},

View File

@ -15,9 +15,9 @@ type GlobalStats struct {
ClientsWifi uint32
ClientsWifi24 uint32
ClientsWifi5 uint32
ClientsOwe uint32
ClientsOwe24 uint32
ClientsOwe5 uint32
ClientsOWE uint32
ClientsOWE24 uint32
ClientsOWE5 uint32
Gateways uint32
Nodes uint32
@ -83,9 +83,9 @@ func (s *GlobalStats) Add(node *Node) {
s.ClientsWifi24 += stats.Clients.Wifi24
s.ClientsWifi5 += stats.Clients.Wifi5
s.ClientsWifi += stats.Clients.Wifi
s.ClientsOwe24 += stats.Clients.Owe24
s.ClientsOwe5 += stats.Clients.Owe5
s.ClientsOwe += stats.Clients.Owe
s.ClientsOWE24 += stats.Clients.OWE24
s.ClientsOWE5 += stats.Clients.OWE5
s.ClientsOWE += stats.Clients.OWE
}
if node.IsGateway() {
s.Gateways++