Skip to content

Commit

Permalink
feat(meshviewer): Add gateway tq and clients owe (#225)
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Maurer <f.maurer@outlook.de>
  • Loading branch information
maurerle authored and genofire committed Sep 18, 2023
1 parent c3588c9 commit 22f67e2
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 41 deletions.
2 changes: 1 addition & 1 deletion data/neighbours.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions data/statistics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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"`
}

Expand Down
6 changes: 3 additions & 3 deletions data/statistics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}) {
Expand Down
6 changes: 3 additions & 3 deletions database/graphite/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
}
}

Expand Down
6 changes: 3 additions & 3 deletions database/graphite/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions database/influxdb/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
6 changes: 3 additions & 3 deletions database/influxdb/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion database/influxdb/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestToInflux(t *testing.T) {
"a-interface-mac": {
Neighbours: map[string]data.BatmanLink{
"BAFF1E5": {
Tq: 204,
TQ: 204,
},
},
},
Expand Down
14 changes: 7 additions & 7 deletions output/meshviewer-ffrgb/meshviewer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
},
},
},
Expand Down Expand Up @@ -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},
},
},
},
Expand Down Expand Up @@ -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},
},
},
},
Expand Down Expand Up @@ -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},
},
},
},
Expand Down
7 changes: 7 additions & 0 deletions output/meshviewer-ffrgb/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ 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"`
Uptime jsontime.Time `json:"uptime,omitempty"`
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"`
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions output/meshviewer/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions output/meshviewer/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions output/prometheus-sd/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion runtime/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion runtime/nodes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
},
Expand Down
12 changes: 6 additions & 6 deletions runtime/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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++
Expand Down

0 comments on commit 22f67e2

Please sign in to comment.