diff --git a/output/meshviewer-ffrgb/struct.go b/output/meshviewer-ffrgb/struct.go index 88707af..233775d 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,15 +105,17 @@ func NewNode(nodes *runtime.Nodes, n *runtime.Node) *Node { node.VPN = nodeinfo.VPN } if statistic := n.Statistics; statistic != nil { - node.Clients = statistic.Clients.Total - node.ClientsWifi24 = statistic.Clients.Wifi24 - node.ClientsWifi5 = statistic.Clients.Wifi5 + if n.Online { + node.Clients = statistic.Clients.Total + node.ClientsWifi24 = statistic.Clients.Wifi24 + node.ClientsWifi5 = statistic.Clients.Wifi5 - clientsWifi := node.ClientsWifi24 + node.ClientsWifi5 - if node.Clients == 0 { - node.Clients = clientsWifi - } else if node.Clients >= clientsWifi { - node.ClientsOthers = node.Clients - clientsWifi + clientsWifi := node.ClientsWifi24 + node.ClientsWifi5 + if node.Clients == 0 { + node.Clients = clientsWifi + } else if node.Clients >= clientsWifi { + node.ClientsOthers = node.Clients - clientsWifi + } } node.RootFSUsage = statistic.RootFsUsage diff --git a/output/meshviewer/node.go b/output/meshviewer/node.go index 8abc49f..4ffeefa 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 cccda96..7f07415 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 2d4eb6e..c9d5611 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 9202d81..c101dde 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 } }