2016-05-29 21:42:11 +02:00
|
|
|
package meshviewer
|
|
|
|
|
|
|
|
import (
|
2017-03-03 16:19:35 +01:00
|
|
|
"github.com/FreifunkBremen/yanic/data"
|
|
|
|
"github.com/FreifunkBremen/yanic/jsontime"
|
2016-05-29 21:42:11 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// Node struct
|
|
|
|
type Node struct {
|
|
|
|
Firstseen jsontime.Time `json:"firstseen"`
|
|
|
|
Lastseen jsontime.Time `json:"lastseen"`
|
2016-10-08 11:41:08 +02:00
|
|
|
Flags Flags `json:"flags"`
|
2016-05-29 21:42:11 +02:00
|
|
|
Statistics *Statistics `json:"statistics"`
|
|
|
|
Nodeinfo *data.NodeInfo `json:"nodeinfo"`
|
|
|
|
Neighbours *data.Neighbours `json:"-"`
|
|
|
|
}
|
|
|
|
|
2017-01-20 22:27:44 +01:00
|
|
|
// Flags status of node set by collector for the meshviewer
|
2016-05-29 21:42:11 +02:00
|
|
|
type Flags struct {
|
|
|
|
Online bool `json:"online"`
|
|
|
|
Gateway bool `json:"gateway"`
|
|
|
|
}
|
|
|
|
|
2017-01-20 22:27:44 +01:00
|
|
|
// Statistics a meshviewer spezifisch struct, diffrent from respondd
|
2016-05-29 21:42:11 +02:00
|
|
|
type Statistics struct {
|
2017-03-16 22:47:35 +01:00
|
|
|
NodeID string `json:"node_id"`
|
|
|
|
Clients uint32 `json:"clients"`
|
|
|
|
RootFsUsage float64 `json:"rootfs_usage,omitempty"`
|
|
|
|
LoadAverage float64 `json:"loadavg,omitempty"`
|
|
|
|
MemoryUsage float64 `json:"memory_usage,omitempty"`
|
|
|
|
Uptime float64 `json:"uptime,omitempty"`
|
|
|
|
Idletime float64 `json:"idletime,omitempty"`
|
|
|
|
GatewayIPv4 string `json:"gateway,omitempty"`
|
|
|
|
GatewayIPv6 string `json:"gateway6,omitempty"`
|
2017-03-14 08:54:46 +01:00
|
|
|
Processes *struct {
|
2016-05-29 21:42:11 +02:00
|
|
|
Total uint32 `json:"total"`
|
|
|
|
Running uint32 `json:"running"`
|
2017-01-20 13:08:58 +01:00
|
|
|
} `json:"processes,omitempty"`
|
2017-01-20 23:23:31 +01:00
|
|
|
MeshVPN *data.MeshVPN `json:"mesh_vpn,omitempty"`
|
2017-03-16 23:30:55 +01:00
|
|
|
Traffic *struct {
|
2016-05-29 21:42:11 +02:00
|
|
|
Tx *data.Traffic `json:"tx"`
|
|
|
|
Rx *data.Traffic `json:"rx"`
|
|
|
|
Forward *data.Traffic `json:"forward"`
|
|
|
|
MgmtTx *data.Traffic `json:"mgmt_tx"`
|
|
|
|
MgmtRx *data.Traffic `json:"mgmt_rx"`
|
2017-01-20 13:08:58 +01:00
|
|
|
} `json:"traffic,omitempty"`
|
2016-05-29 21:42:11 +02:00
|
|
|
}
|
2017-01-20 14:38:13 +01:00
|
|
|
|
2017-01-20 22:27:44 +01:00
|
|
|
// NewStatistics transform respond Statistics to meshviewer Statistics
|
2017-01-20 14:38:13 +01:00
|
|
|
func NewStatistics(stats *data.Statistics) *Statistics {
|
2017-03-14 08:54:46 +01:00
|
|
|
var total uint32
|
|
|
|
if clients := stats.Clients; clients != nil {
|
|
|
|
total = clients.Total
|
|
|
|
if total <= 0 {
|
|
|
|
total = clients.Wifi24 + clients.Wifi5
|
|
|
|
}
|
2017-01-20 14:38:13 +01:00
|
|
|
}
|
|
|
|
/* The Meshviewer could not handle absolute memory output
|
2017-03-13 18:36:39 +01:00
|
|
|
* 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)
|
2017-01-20 22:27:44 +01:00
|
|
|
*/
|
2017-01-20 14:38:13 +01:00
|
|
|
|
2017-03-16 22:47:35 +01:00
|
|
|
result := &Statistics{
|
2017-01-20 22:27:44 +01:00
|
|
|
NodeID: stats.NodeID,
|
2017-03-06 20:18:08 +01:00
|
|
|
GatewayIPv4: stats.GatewayIPv4,
|
|
|
|
GatewayIPv6: stats.GatewayIPv6,
|
2017-01-20 14:38:13 +01:00
|
|
|
RootFsUsage: stats.RootFsUsage,
|
|
|
|
LoadAverage: stats.LoadAverage,
|
|
|
|
Uptime: stats.Uptime,
|
|
|
|
Idletime: stats.Idletime,
|
|
|
|
Processes: stats.Processes,
|
2017-01-20 23:23:31 +01:00
|
|
|
MeshVPN: stats.MeshVPN,
|
2017-01-20 14:38:13 +01:00
|
|
|
Traffic: stats.Traffic,
|
|
|
|
Clients: total,
|
2017-03-16 22:47:35 +01:00
|
|
|
MemoryUsage: 1,
|
2017-01-20 14:38:13 +01:00
|
|
|
}
|
2017-03-14 08:54:46 +01:00
|
|
|
if memory := stats.Memory; memory != nil && memory.Total > 0 {
|
2017-03-16 22:47:35 +01:00
|
|
|
result.MemoryUsage = 1 - (float64(memory.Free)+float64(memory.Buffers)+float64(memory.Cached))/float64(memory.Total)
|
2017-03-14 08:54:46 +01:00
|
|
|
}
|
2017-03-16 22:47:35 +01:00
|
|
|
return result
|
2017-01-20 14:38:13 +01:00
|
|
|
}
|