[BUGFIX] meshviewer divide by zero
This commit is contained in:
parent
dc24c8b250
commit
e9c9968980
|
@ -15,10 +15,9 @@ type WirelessStatistics []*WirelessAirtime
|
||||||
|
|
||||||
// WirelessAirtime struct
|
// WirelessAirtime struct
|
||||||
type WirelessAirtime struct {
|
type WirelessAirtime struct {
|
||||||
ChanUtil float32 // Channel utilization
|
ChanUtil float32 `json:"chan_util"` // Channel utilization
|
||||||
RxUtil float32 // Receive utilization
|
RxUtil float32 `json:"rx_util"` // Receive utilization
|
||||||
TxUtil float32 // Transmit utilization
|
TxUtil float32 `json:"tx_util"` // Transmit utilization
|
||||||
|
|
||||||
ActiveTime uint64 `json:"active"`
|
ActiveTime uint64 `json:"active"`
|
||||||
BusyTime uint64 `json:"busy"`
|
BusyTime uint64 `json:"busy"`
|
||||||
RxTime uint64 `json:"rx"`
|
RxTime uint64 `json:"rx"`
|
||||||
|
|
|
@ -8,16 +8,16 @@ package data
|
||||||
//Statistics struct
|
//Statistics struct
|
||||||
type Statistics struct {
|
type Statistics struct {
|
||||||
NodeID string `json:"node_id"`
|
NodeID string `json:"node_id"`
|
||||||
Clients Clients `json:"clients"`
|
Clients *Clients `json:"clients"`
|
||||||
RootFsUsage float64 `json:"rootfs_usage,omitempty"`
|
RootFsUsage float64 `json:"rootfs_usage,omitempty"`
|
||||||
LoadAverage float64 `json:"loadavg,omitempty"`
|
LoadAverage float64 `json:"loadavg,omitempty"`
|
||||||
Memory Memory `json:"memory,omitempty"`
|
Memory *Memory `json:"memory,omitempty"`
|
||||||
Uptime float64 `json:"uptime,omitempty"`
|
Uptime float64 `json:"uptime,omitempty"`
|
||||||
Idletime float64 `json:"idletime,omitempty"`
|
Idletime float64 `json:"idletime,omitempty"`
|
||||||
GatewayIPv4 string `json:"gateway,omitempty"`
|
GatewayIPv4 string `json:"gateway,omitempty"`
|
||||||
GatewayIPv6 string `json:"gateway6,omitempty"`
|
GatewayIPv6 string `json:"gateway6,omitempty"`
|
||||||
GatewayNexthop string `json:"gateway_nexthop,omitempty"`
|
GatewayNexthop string `json:"gateway_nexthop,omitempty"`
|
||||||
Processes struct {
|
Processes *struct {
|
||||||
Total uint32 `json:"total"`
|
Total uint32 `json:"total"`
|
||||||
Running uint32 `json:"running"`
|
Running uint32 `json:"running"`
|
||||||
} `json:"processes,omitempty"`
|
} `json:"processes,omitempty"`
|
||||||
|
|
|
@ -32,15 +32,24 @@ func buildNodeStats(node *runtime.Node) (tags models.Tags, fields models.Fields)
|
||||||
"load": stats.LoadAverage,
|
"load": stats.LoadAverage,
|
||||||
"time.up": int64(stats.Uptime),
|
"time.up": int64(stats.Uptime),
|
||||||
"time.idle": int64(stats.Idletime),
|
"time.idle": int64(stats.Idletime),
|
||||||
"proc.running": stats.Processes.Running,
|
}
|
||||||
"clients.wifi": stats.Clients.Wifi,
|
|
||||||
"clients.wifi24": stats.Clients.Wifi24,
|
if clients := stats.Clients; clients != nil {
|
||||||
"clients.wifi5": stats.Clients.Wifi5,
|
fields["clients.wifi"] = clients.Wifi
|
||||||
"clients.total": stats.Clients.Total,
|
fields["clients.wifi24"] = clients.Wifi24
|
||||||
"memory.buffers": stats.Memory.Buffers,
|
fields["clients.wifi5"] = clients.Wifi5
|
||||||
"memory.cached": stats.Memory.Cached,
|
fields["clients.total"] = clients.Total
|
||||||
"memory.free": stats.Memory.Free,
|
}
|
||||||
"memory.total": stats.Memory.Total,
|
|
||||||
|
if proc := stats.Processes; proc != nil {
|
||||||
|
fields["proc.running"] = stats.Processes.Running
|
||||||
|
}
|
||||||
|
|
||||||
|
if mem := stats.Memory; mem != nil {
|
||||||
|
fields["memory.buffers"] = mem.Buffers
|
||||||
|
fields["memory.cached"] = mem.Cached
|
||||||
|
fields["memory.free"] = mem.Free
|
||||||
|
fields["memory.total"] = mem.Total
|
||||||
}
|
}
|
||||||
|
|
||||||
if nodeinfo := node.Nodeinfo; nodeinfo != nil {
|
if nodeinfo := node.Nodeinfo; nodeinfo != nil {
|
||||||
|
|
|
@ -27,12 +27,12 @@ type Statistics struct {
|
||||||
Clients uint32 `json:"clients"`
|
Clients uint32 `json:"clients"`
|
||||||
RootFsUsage float64 `json:"rootfs_usage,omitempty"`
|
RootFsUsage float64 `json:"rootfs_usage,omitempty"`
|
||||||
LoadAverage float64 `json:"loadavg,omitempty"`
|
LoadAverage float64 `json:"loadavg,omitempty"`
|
||||||
MemoryUsage float64 `json:"memory_usage,omitempty"`
|
MemoryUsage *float64 `json:"memory_usage,omitempty"`
|
||||||
Uptime float64 `json:"uptime,omitempty"`
|
Uptime float64 `json:"uptime,omitempty"`
|
||||||
Idletime float64 `json:"idletime,omitempty"`
|
Idletime float64 `json:"idletime,omitempty"`
|
||||||
GatewayIPv4 string `json:"gateway,omitempty"`
|
GatewayIPv4 string `json:"gateway,omitempty"`
|
||||||
GatewayIPv6 string `json:"gateway6,omitempty"`
|
GatewayIPv6 string `json:"gateway6,omitempty"`
|
||||||
Processes struct {
|
Processes *struct {
|
||||||
Total uint32 `json:"total"`
|
Total uint32 `json:"total"`
|
||||||
Running uint32 `json:"running"`
|
Running uint32 `json:"running"`
|
||||||
} `json:"processes,omitempty"`
|
} `json:"processes,omitempty"`
|
||||||
|
@ -48,24 +48,25 @@ 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) *Statistics {
|
||||||
total := stats.Clients.Total
|
var total uint32
|
||||||
if total == 0 {
|
if clients := stats.Clients; clients != nil {
|
||||||
total = stats.Clients.Wifi24 + stats.Clients.Wifi5
|
total = clients.Total
|
||||||
|
if total <= 0 {
|
||||||
|
total = clients.Wifi24 + clients.Wifi5
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* The Meshviewer could not handle absolute memory output
|
/* The Meshviewer could not handle absolute memory output
|
||||||
* calc the used memory as a float which 100% equal 1.0
|
* calc the used memory as a float which 100% equal 1.0
|
||||||
* calc is coppied from node statuspage (look discussion:
|
* calc is coppied from node statuspage (look discussion:
|
||||||
* https://github.com/FreifunkBremen/yanic/issues/35)
|
* https://github.com/FreifunkBremen/yanic/issues/35)
|
||||||
*/
|
*/
|
||||||
memoryUsage := 1 - (float64(stats.Memory.Free)+float64(stats.Memory.Buffers)+float64(stats.Memory.Cached))/float64(stats.Memory.Total)
|
|
||||||
|
|
||||||
return &Statistics{
|
meshviewerStats := &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,
|
||||||
|
@ -73,4 +74,8 @@ func NewStatistics(stats *data.Statistics) *Statistics {
|
||||||
Traffic: stats.Traffic,
|
Traffic: stats.Traffic,
|
||||||
Clients: total,
|
Clients: total,
|
||||||
}
|
}
|
||||||
|
if memory := stats.Memory; memory != nil && memory.Total > 0 {
|
||||||
|
*meshviewerStats.MemoryUsage = 1 - (float64(memory.Free)+float64(memory.Buffers)+float64(memory.Cached))/float64(memory.Total)
|
||||||
|
}
|
||||||
|
return meshviewerStats
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ func NewGlobalStats(nodes *Nodes) (result *GlobalStats) {
|
||||||
for _, node := range nodes.List {
|
for _, node := range nodes.List {
|
||||||
if node.Online {
|
if node.Online {
|
||||||
result.Nodes++
|
result.Nodes++
|
||||||
if stats := node.Statistics; stats != nil {
|
if stats := node.Statistics; stats != nil && stats.Clients != nil {
|
||||||
result.Clients += stats.Clients.Total
|
result.Clients += stats.Clients.Total
|
||||||
result.ClientsWifi24 += stats.Clients.Wifi24
|
result.ClientsWifi24 += stats.Clients.Wifi24
|
||||||
result.ClientsWifi5 += stats.Clients.Wifi5
|
result.ClientsWifi5 += stats.Clients.Wifi5
|
||||||
|
|
|
@ -31,7 +31,7 @@ func createTestNodes() *Nodes {
|
||||||
|
|
||||||
nodeData := &data.ResponseData{
|
nodeData := &data.ResponseData{
|
||||||
Statistics: &data.Statistics{
|
Statistics: &data.Statistics{
|
||||||
Clients: data.Clients{
|
Clients: &data.Clients{
|
||||||
Total: 23,
|
Total: 23,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -46,7 +46,7 @@ func createTestNodes() *Nodes {
|
||||||
|
|
||||||
nodes.Update("112233445566", &data.ResponseData{
|
nodes.Update("112233445566", &data.ResponseData{
|
||||||
Statistics: &data.Statistics{
|
Statistics: &data.Statistics{
|
||||||
Clients: data.Clients{
|
Clients: &data.Clients{
|
||||||
Total: 2,
|
Total: 2,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue