parent
8fffdac0a4
commit
3422a29254
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user