From 0dafc34aefaff66c0e1776439a52e7b4bca928d4 Mon Sep 17 00:00:00 2001 From: Martin Geno Date: Wed, 27 Dec 2017 02:12:15 +0100 Subject: [PATCH] [TASK] show online clients in output if online --- output/meshviewer-ffrgb/struct.go | 22 +++++++++-------- output/meshviewer/node.go | 40 ++++++++++++++++--------------- output/meshviewer/nodes_v1.go | 2 +- output/meshviewer/nodes_v2.go | 2 +- output/nodelist/nodelist.go | 2 +- 5 files changed, 36 insertions(+), 32 deletions(-) diff --git a/output/meshviewer-ffrgb/struct.go b/output/meshviewer-ffrgb/struct.go index b84627f6..ec8868ee 100644 --- a/output/meshviewer-ffrgb/struct.go +++ b/output/meshviewer-ffrgb/struct.go @@ -92,7 +92,7 @@ func NewNode(nodes *runtime.Nodes, n *runtime.Node) *Node { if location := nodeinfo.Location; location != nil { node.Location = &Location{ Longitude: location.Longitude, - Latitude: location.Latitude, + Latitude: location.Latitude, } } node.Firmware = nodeinfo.Software.Firmware @@ -105,16 +105,18 @@ func NewNode(nodes *runtime.Nodes, n *runtime.Node) *Node { node.VPN = nodeinfo.VPN } if statistic := n.Statistics; statistic != nil { - node.Clients = statistic.Clients.Total - if node.Clients == 0 { - node.Clients = statistic.Clients.Wifi24 + statistic.Clients.Wifi5 - } - node.ClientsWifi24 = statistic.Clients.Wifi24 - node.ClientsWifi5 = statistic.Clients.Wifi5 + if n.Online { + node.Clients = statistic.Clients.Total + if node.Clients == 0 { + node.Clients = statistic.Clients.Wifi24 + statistic.Clients.Wifi5 + } + node.ClientsWifi24 = statistic.Clients.Wifi24 + node.ClientsWifi5 = statistic.Clients.Wifi5 - wifi := node.ClientsWifi24 - node.ClientsWifi5 - if node.Clients >= wifi { - node.ClientsOthers = node.Clients - wifi + wifi := node.ClientsWifi24 - node.ClientsWifi5 + if node.Clients >= wifi { + node.ClientsOthers = node.Clients - wifi + } } node.RootFSUsage = statistic.RootFsUsage diff --git a/output/meshviewer/node.go b/output/meshviewer/node.go index 8abc49f7..4ffeefa6 100644 --- a/output/meshviewer/node.go +++ b/output/meshviewer/node.go @@ -47,34 +47,36 @@ type Statistics struct { } // NewStatistics transform respond Statistics to meshviewer Statistics -func NewStatistics(stats *data.Statistics) *Statistics { - total := stats.Clients.Total - if total == 0 { - total = stats.Clients.Wifi24 + stats.Clients.Wifi5 - } - /* The Meshviewer could not handle absolute memory output - * calc the used memory as a float which 100% equal 1.0 - * calc is coppied from node statuspage (look discussion: - * https://github.com/FreifunkBremen/yanic/issues/35) - */ - var memoryUsage *float64 - if stats.Memory.Total > 0 { - usage := 1 - (float64(stats.Memory.Free)+float64(stats.Memory.Buffers)+float64(stats.Memory.Cached))/float64(stats.Memory.Total) - memoryUsage = &usage - } - - return &Statistics{ +func NewStatistics(stats *data.Statistics, isOnline bool) *Statistics { + output := &Statistics{ NodeID: stats.NodeID, GatewayIPv4: stats.GatewayIPv4, GatewayIPv6: stats.GatewayIPv6, RootFsUsage: stats.RootFsUsage, LoadAverage: stats.LoadAverage, - MemoryUsage: memoryUsage, Uptime: stats.Uptime, Idletime: stats.Idletime, Processes: stats.Processes, MeshVPN: stats.MeshVPN, Traffic: stats.Traffic, - Clients: total, } + if isOnline { + total := stats.Clients.Total + if total == 0 { + total = stats.Clients.Wifi24 + stats.Clients.Wifi5 + } + output.Clients = total + } + + /* The Meshviewer could not handle absolute memory output + * calc the used memory as a float which 100% equal 1.0 + * calc is coppied from node statuspage (look discussion: + * https://github.com/FreifunkBremen/yanic/issues/35) + */ + if stats.Memory.Total > 0 { + usage := 1 - (float64(stats.Memory.Free)+float64(stats.Memory.Buffers)+float64(stats.Memory.Cached))/float64(stats.Memory.Total) + output.MemoryUsage = &usage + } + + return output } diff --git a/output/meshviewer/nodes_v1.go b/output/meshviewer/nodes_v1.go index cccda965..7f074155 100644 --- a/output/meshviewer/nodes_v1.go +++ b/output/meshviewer/nodes_v1.go @@ -35,7 +35,7 @@ func BuildNodesV1(nodes *runtime.Nodes) interface{} { }, Nodeinfo: nodeOrigin.Nodeinfo, } - node.Statistics = NewStatistics(nodeOrigin.Statistics) + node.Statistics = NewStatistics(nodeOrigin.Statistics, nodeOrigin.Online) meshviewerNodes.List[nodeID] = node } return meshviewerNodes diff --git a/output/meshviewer/nodes_v2.go b/output/meshviewer/nodes_v2.go index 2d4eb6e0..c9d5611e 100644 --- a/output/meshviewer/nodes_v2.go +++ b/output/meshviewer/nodes_v2.go @@ -33,7 +33,7 @@ func BuildNodesV2(nodes *runtime.Nodes) interface{} { }, Nodeinfo: nodeOrigin.Nodeinfo, } - node.Statistics = NewStatistics(nodeOrigin.Statistics) + node.Statistics = NewStatistics(nodeOrigin.Statistics, nodeOrigin.Online) meshviewerNodes.List = append(meshviewerNodes.List, node) } return meshviewerNodes diff --git a/output/nodelist/nodelist.go b/output/nodelist/nodelist.go index 9202d81a..c101ddec 100644 --- a/output/nodelist/nodelist.go +++ b/output/nodelist/nodelist.go @@ -40,7 +40,7 @@ func NewNode(n *runtime.Node) (node *Node) { node.Status.Online = n.Online node.Status.LastContact = n.Lastseen - if statistics := n.Statistics; statistics != nil { + if statistics := n.Statistics; statistics != nil && n.Online { node.Status.Clients = statistics.Clients.Total } }