parent
8fffdac0a4
commit
3422a29254
@ -105,6 +105,7 @@ func NewNode(nodes *runtime.Nodes, n *runtime.Node) *Node {
|
|||||||
node.VPN = nodeinfo.VPN
|
node.VPN = nodeinfo.VPN
|
||||||
}
|
}
|
||||||
if statistic := n.Statistics; statistic != nil {
|
if statistic := n.Statistics; statistic != nil {
|
||||||
|
if n.Online {
|
||||||
node.Clients = statistic.Clients.Total
|
node.Clients = statistic.Clients.Total
|
||||||
node.ClientsWifi24 = statistic.Clients.Wifi24
|
node.ClientsWifi24 = statistic.Clients.Wifi24
|
||||||
node.ClientsWifi5 = statistic.Clients.Wifi5
|
node.ClientsWifi5 = statistic.Clients.Wifi5
|
||||||
@ -115,6 +116,7 @@ func NewNode(nodes *runtime.Nodes, n *runtime.Node) *Node {
|
|||||||
} else if node.Clients >= clientsWifi {
|
} else if node.Clients >= clientsWifi {
|
||||||
node.ClientsOthers = node.Clients - clientsWifi
|
node.ClientsOthers = node.Clients - clientsWifi
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
node.RootFSUsage = statistic.RootFsUsage
|
node.RootFSUsage = statistic.RootFsUsage
|
||||||
node.LoadAverage = statistic.LoadAverage
|
node.LoadAverage = statistic.LoadAverage
|
||||||
|
@ -47,34 +47,36 @@ type Statistics struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewStatistics transform respond Statistics to meshviewer Statistics
|
// NewStatistics transform respond Statistics to meshviewer Statistics
|
||||||
func NewStatistics(stats *data.Statistics) *Statistics {
|
func NewStatistics(stats *data.Statistics, isOnline bool) *Statistics {
|
||||||
total := stats.Clients.Total
|
output := &Statistics{
|
||||||
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{
|
|
||||||
NodeID: stats.NodeID,
|
NodeID: stats.NodeID,
|
||||||
GatewayIPv4: stats.GatewayIPv4,
|
GatewayIPv4: stats.GatewayIPv4,
|
||||||
GatewayIPv6: stats.GatewayIPv6,
|
GatewayIPv6: stats.GatewayIPv6,
|
||||||
RootFsUsage: stats.RootFsUsage,
|
RootFsUsage: stats.RootFsUsage,
|
||||||
LoadAverage: stats.LoadAverage,
|
LoadAverage: stats.LoadAverage,
|
||||||
MemoryUsage: memoryUsage,
|
|
||||||
Uptime: stats.Uptime,
|
Uptime: stats.Uptime,
|
||||||
Idletime: stats.Idletime,
|
Idletime: stats.Idletime,
|
||||||
Processes: stats.Processes,
|
Processes: stats.Processes,
|
||||||
MeshVPN: stats.MeshVPN,
|
MeshVPN: stats.MeshVPN,
|
||||||
Traffic: stats.Traffic,
|
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,
|
Nodeinfo: nodeOrigin.Nodeinfo,
|
||||||
}
|
}
|
||||||
node.Statistics = NewStatistics(nodeOrigin.Statistics)
|
node.Statistics = NewStatistics(nodeOrigin.Statistics, nodeOrigin.Online)
|
||||||
meshviewerNodes.List[nodeID] = node
|
meshviewerNodes.List[nodeID] = node
|
||||||
}
|
}
|
||||||
return meshviewerNodes
|
return meshviewerNodes
|
||||||
|
@ -33,7 +33,7 @@ func BuildNodesV2(nodes *runtime.Nodes) interface{} {
|
|||||||
},
|
},
|
||||||
Nodeinfo: nodeOrigin.Nodeinfo,
|
Nodeinfo: nodeOrigin.Nodeinfo,
|
||||||
}
|
}
|
||||||
node.Statistics = NewStatistics(nodeOrigin.Statistics)
|
node.Statistics = NewStatistics(nodeOrigin.Statistics, nodeOrigin.Online)
|
||||||
meshviewerNodes.List = append(meshviewerNodes.List, node)
|
meshviewerNodes.List = append(meshviewerNodes.List, node)
|
||||||
}
|
}
|
||||||
return meshviewerNodes
|
return meshviewerNodes
|
||||||
|
@ -40,7 +40,7 @@ func NewNode(n *runtime.Node) (node *Node) {
|
|||||||
|
|
||||||
node.Status.Online = n.Online
|
node.Status.Online = n.Online
|
||||||
node.Status.LastContact = n.Lastseen
|
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
|
node.Status.Clients = statistics.Clients.Total
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user