add Flags and MeshviewerStatistics for old meshviewer nodes.json
This commit is contained in:
parent
18acdd7642
commit
54e54f8256
|
@ -8,16 +8,16 @@ package data
|
|||
type Statistics struct {
|
||||
NodeId string `json:"node_id"`
|
||||
Clients Clients `json:"clients"`
|
||||
RootFsUsage float64 `json:"rootfs_usage"`
|
||||
LoadAverage float64 `json:"loadavg"`
|
||||
Memory Memory `json:"memory"`
|
||||
Uptime float64 `json:"uptime"`
|
||||
Idletime float64 `json:"idletime"`
|
||||
Gateway string `json:"gateway"`
|
||||
RootFsUsage float64 `json:"rootfs_usage,omitempty""`
|
||||
LoadAverage float64 `json:"loadavg,omitempty""`
|
||||
Memory Memory `json:"memory,omitempty""`
|
||||
Uptime float64 `json:"uptime,omitempty""`
|
||||
Idletime float64 `json:"idletime,omitempty""`
|
||||
Gateway string `json:"gateway,omitempty""`
|
||||
Processes struct {
|
||||
Total uint32 `json:"total"`
|
||||
Running uint32 `json:"running"`
|
||||
} `json:"processes"`
|
||||
} `json:"processes,omitempty""`
|
||||
MeshVpn *MeshVPN `json:"mesh_vpn,omitempty"`
|
||||
Traffic struct {
|
||||
Tx *Traffic `json:"tx"`
|
||||
|
@ -25,7 +25,7 @@ type Statistics struct {
|
|||
Forward *Traffic `json:"forward"`
|
||||
MgmtTx *Traffic `json:"mgmt_tx"`
|
||||
MgmtRx *Traffic `json:"mgmt_rx"`
|
||||
} `json:"traffic"`
|
||||
} `json:"traffic,omitempty""`
|
||||
}
|
||||
|
||||
type MeshVPNPeerLink struct {
|
||||
|
|
|
@ -44,17 +44,16 @@ func (builder *GraphBuilder) readNodes(nodes map[string]*Node) {
|
|||
// Fill mac->id map
|
||||
for sourceId, node := range nodes {
|
||||
if nodeinfo := node.Nodeinfo; nodeinfo != nil {
|
||||
// is VPN address?
|
||||
if nodeinfo.VPN {
|
||||
builder.vpn[sourceId] = nil
|
||||
}
|
||||
for _,batinterface := range nodeinfo.Network.Mesh {
|
||||
interfaces := batinterface.Interfaces
|
||||
addresses := append(append(interfaces.Other, interfaces.Tunnel...), interfaces.Wireless...)
|
||||
|
||||
for _, sourceAddress := range addresses {
|
||||
builder.macToID[sourceAddress] = sourceId
|
||||
|
||||
// is VPN address?
|
||||
if _, found := builder.vpn[sourceAddress]; found {
|
||||
builder.vpn[sourceId] = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,13 +16,16 @@ import (
|
|||
type Node struct {
|
||||
Firstseen jsontime.Time `json:"firstseen"`
|
||||
Lastseen jsontime.Time `json:"lastseen"`
|
||||
Flags *Flags `json:"flags,omitempty"`
|
||||
//Statistics *MeshviewerStatistics `json:"statistics"`
|
||||
Statistics *data.Statistics `json:"statistics"`
|
||||
Nodeinfo *data.NodeInfo `json:"nodeinfo"`
|
||||
Neighbours *data.Neighbours `json:"-"`
|
||||
}
|
||||
|
||||
type NodeElement struct {
|
||||
NodeId string
|
||||
type Flags struct {
|
||||
Online bool `json:"online"`
|
||||
Gateway bool `json:"gateway"`
|
||||
}
|
||||
|
||||
// Nodes struct: cache DB of Node's structs
|
||||
|
@ -60,6 +63,10 @@ func (nodes *Nodes) Update(nodeID string, res *data.ResponseData) {
|
|||
if node == nil {
|
||||
node = &Node{
|
||||
Firstseen: now,
|
||||
Flags: &Flags{
|
||||
Online: true,
|
||||
Gateway: false,
|
||||
},
|
||||
}
|
||||
nodes.List[nodeID] = node
|
||||
}
|
||||
|
@ -75,11 +82,27 @@ func (nodes *Nodes) Update(nodeID string, res *data.ResponseData) {
|
|||
// Update nodeinfo
|
||||
if val := res.NodeInfo; val != nil {
|
||||
node.Nodeinfo = val
|
||||
node.Flags.Gateway = val.VPN
|
||||
}
|
||||
|
||||
// Update statistics
|
||||
if val := res.Statistics; val != nil {
|
||||
node.Statistics = val
|
||||
//node.Statistics = &MeshviewerStatistics{
|
||||
node.Statistics = &data.Statistics{
|
||||
NodeId: val.NodeId,
|
||||
// Clients: 0,
|
||||
Gateway: val.Gateway,
|
||||
RootFsUsage: val.RootFsUsage,
|
||||
LoadAverage: val.LoadAverage,
|
||||
Memory: val.Memory,
|
||||
Uptime: val.Uptime,
|
||||
Idletime: val.Idletime,
|
||||
Processes: val.Processes,
|
||||
MeshVpn: val.MeshVpn,
|
||||
Traffic: val.Traffic,
|
||||
}
|
||||
//node.Statistics.Clients = val.Clients.Total
|
||||
node.Statistics.Clients = val.Clients
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,6 +115,21 @@ func (nodes *Nodes) worker() {
|
|||
nodes.Timestamp = jsontime.Now()
|
||||
nodes.Lock()
|
||||
|
||||
// set node as offline (without statistics)
|
||||
for _,node := range nodes.List {
|
||||
if node.Statistics != nil && node.Lastseen.Unix()+int64(5*nodes.config.Respondd.CollectInterval) < nodes.Timestamp.Unix() {
|
||||
// node.Statistics.Clients = data.Clients{Wifi: 0, Wifi24: 0, Wifi5: 0, Total: 0}
|
||||
// node.Statistics = &MeshviewerStatistics{
|
||||
node.Statistics = &data.Statistics{
|
||||
NodeId: node.Statistics.NodeId,
|
||||
//Clients: 0,
|
||||
Clients: data.Clients{Wifi: 0, Wifi24: 0, Wifi5: 0, Total: 0},
|
||||
}
|
||||
if node.Flags != nil {
|
||||
node.Flags.Online = false
|
||||
}
|
||||
}
|
||||
}
|
||||
// serialize nodes
|
||||
save(nodes, nodes.config.Nodes.NodesPath)
|
||||
|
||||
|
|
Loading…
Reference in New Issue