Skip to content

Commit

Permalink
[TASK] show online clients in output only if online
Browse files Browse the repository at this point in the history
  • Loading branch information
genofire committed Dec 28, 2017
1 parent 8fffdac commit 2024c63
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 31 deletions.
20 changes: 11 additions & 9 deletions output/meshviewer-ffrgb/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
40 changes: 21 additions & 19 deletions output/meshviewer/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion output/meshviewer/nodes_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion output/meshviewer/nodes_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion output/nodelist/nodelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down

0 comments on commit 2024c63

Please sign in to comment.