From 22f67e2d4dbb50655ea03de2cd4946939a90b093 Mon Sep 17 00:00:00 2001 From: Florian Maurer Date: Mon, 18 Sep 2023 19:56:18 +0200 Subject: [PATCH] feat(meshviewer): Add gateway tq and clients owe (#225) Signed-off-by: Florian Maurer --- data/neighbours.go | 2 +- data/statistics.go | 7 ++++--- data/statistics_test.go | 6 +++--- database/graphite/global.go | 6 +++--- database/graphite/node.go | 6 +++--- database/influxdb/global.go | 6 +++--- database/influxdb/node.go | 6 +++--- database/influxdb/node_test.go | 2 +- output/meshviewer-ffrgb/meshviewer_test.go | 14 +++++++------- output/meshviewer-ffrgb/struct.go | 7 +++++++ output/meshviewer/graph.go | 8 ++++---- output/meshviewer/node.go | 3 +++ output/prometheus-sd/output_test.go | 4 ++-- runtime/nodes.go | 2 +- runtime/nodes_test.go | 2 +- runtime/stats.go | 12 ++++++------ 16 files changed, 52 insertions(+), 41 deletions(-) diff --git a/data/neighbours.go b/data/neighbours.go index d6454a89..649399e2 100644 --- a/data/neighbours.go +++ b/data/neighbours.go @@ -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 diff --git a/data/statistics.go b/data/statistics.go index bec0a7f1..7d284c12 100644 --- a/data/statistics.go +++ b/data/statistics.go @@ -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"` } diff --git a/data/statistics_test.go b/data/statistics_test.go index 2a2cdf77..262faf96 100644 --- a/data/statistics_test.go +++ b/data/statistics_test.go @@ -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{}) { diff --git a/database/graphite/global.go b/database/graphite/global.go index 936ff704..6e373b77 100644 --- a/database/graphite/global.go +++ b/database/graphite/global.go @@ -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}, } } diff --git a/database/graphite/node.go b/database/graphite/node.go index fe670918..891a4f81 100644 --- a/database/graphite/node.go +++ b/database/graphite/node.go @@ -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) diff --git a/database/influxdb/global.go b/database/influxdb/global.go index 7fc3fb34..e5dc10b6 100644 --- a/database/influxdb/global.go +++ b/database/influxdb/global.go @@ -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, } } diff --git a/database/influxdb/node.go b/database/influxdb/node.go index 06572636..eb13f4b4 100644 --- a/database/influxdb/node.go +++ b/database/influxdb/node.go @@ -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, diff --git a/database/influxdb/node_test.go b/database/influxdb/node_test.go index 5b784b37..229fa783 100644 --- a/database/influxdb/node_test.go +++ b/database/influxdb/node_test.go @@ -83,7 +83,7 @@ func TestToInflux(t *testing.T) { "a-interface-mac": { Neighbours: map[string]data.BatmanLink{ "BAFF1E5": { - Tq: 204, + TQ: 204, }, }, }, diff --git a/output/meshviewer-ffrgb/meshviewer_test.go b/output/meshviewer-ffrgb/meshviewer_test.go index 2715aea9..b03dbf21 100644 --- a/output/meshviewer-ffrgb/meshviewer_test.go +++ b/output/meshviewer-ffrgb/meshviewer_test.go @@ -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}, }, }, }, diff --git a/output/meshviewer-ffrgb/struct.go b/output/meshviewer-ffrgb/struct.go index 1b4f5e3d..44362198 100644 --- a/output/meshviewer-ffrgb/struct.go +++ b/output/meshviewer-ffrgb/struct.go @@ -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 { diff --git a/output/meshviewer/graph.go b/output/meshviewer/graph.go index 9d34d5b1..55725bb3 100644 --- a/output/meshviewer/graph.go +++ b/output/meshviewer/graph.go @@ -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 { diff --git a/output/meshviewer/node.go b/output/meshviewer/node.go index bb3bb744..f92de361 100644 --- a/output/meshviewer/node.go +++ b/output/meshviewer/node.go @@ -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, diff --git a/output/prometheus-sd/output_test.go b/output/prometheus-sd/output_test.go index 8cbfe9aa..c0294636 100644 --- a/output/prometheus-sd/output_test.go +++ b/output/prometheus-sd/output_test.go @@ -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}, }, }, }, diff --git a/runtime/nodes.go b/runtime/nodes.go index 37cf0a65..7db9f730 100644 --- a/runtime/nodes.go +++ b/runtime/nodes.go @@ -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 { diff --git a/runtime/nodes_test.go b/runtime/nodes_test.go index 1d8d65db..fb2ad32c 100644 --- a/runtime/nodes_test.go +++ b/runtime/nodes_test.go @@ -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, }, }, }, diff --git a/runtime/stats.go b/runtime/stats.go index 50d30e3e..b4cbb7d9 100644 --- a/runtime/stats.go +++ b/runtime/stats.go @@ -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++