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 {
|
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"`
|
RootFsUsage float64 `json:"rootfs_usage,omitempty""`
|
||||||
LoadAverage float64 `json:"loadavg"`
|
LoadAverage float64 `json:"loadavg,omitempty""`
|
||||||
Memory Memory `json:"memory"`
|
Memory Memory `json:"memory,omitempty""`
|
||||||
Uptime float64 `json:"uptime"`
|
Uptime float64 `json:"uptime,omitempty""`
|
||||||
Idletime float64 `json:"idletime"`
|
Idletime float64 `json:"idletime,omitempty""`
|
||||||
Gateway string `json:"gateway"`
|
Gateway string `json:"gateway,omitempty""`
|
||||||
Processes struct {
|
Processes struct {
|
||||||
Total uint32 `json:"total"`
|
Total uint32 `json:"total"`
|
||||||
Running uint32 `json:"running"`
|
Running uint32 `json:"running"`
|
||||||
} `json:"processes"`
|
} `json:"processes,omitempty""`
|
||||||
MeshVpn *MeshVPN `json:"mesh_vpn,omitempty"`
|
MeshVpn *MeshVPN `json:"mesh_vpn,omitempty"`
|
||||||
Traffic struct {
|
Traffic struct {
|
||||||
Tx *Traffic `json:"tx"`
|
Tx *Traffic `json:"tx"`
|
||||||
@ -25,7 +25,7 @@ type Statistics struct {
|
|||||||
Forward *Traffic `json:"forward"`
|
Forward *Traffic `json:"forward"`
|
||||||
MgmtTx *Traffic `json:"mgmt_tx"`
|
MgmtTx *Traffic `json:"mgmt_tx"`
|
||||||
MgmtRx *Traffic `json:"mgmt_rx"`
|
MgmtRx *Traffic `json:"mgmt_rx"`
|
||||||
} `json:"traffic"`
|
} `json:"traffic,omitempty""`
|
||||||
}
|
}
|
||||||
|
|
||||||
type MeshVPNPeerLink struct {
|
type MeshVPNPeerLink struct {
|
||||||
|
@ -44,17 +44,16 @@ func (builder *GraphBuilder) readNodes(nodes map[string]*Node) {
|
|||||||
// Fill mac->id map
|
// Fill mac->id map
|
||||||
for sourceId, node := range nodes {
|
for sourceId, node := range nodes {
|
||||||
if nodeinfo := node.Nodeinfo; nodeinfo != nil {
|
if nodeinfo := node.Nodeinfo; nodeinfo != nil {
|
||||||
|
// is VPN address?
|
||||||
|
if nodeinfo.VPN {
|
||||||
|
builder.vpn[sourceId] = nil
|
||||||
|
}
|
||||||
for _,batinterface := range nodeinfo.Network.Mesh {
|
for _,batinterface := range nodeinfo.Network.Mesh {
|
||||||
interfaces := batinterface.Interfaces
|
interfaces := batinterface.Interfaces
|
||||||
addresses := append(append(interfaces.Other, interfaces.Tunnel...), interfaces.Wireless...)
|
addresses := append(append(interfaces.Other, interfaces.Tunnel...), interfaces.Wireless...)
|
||||||
|
|
||||||
for _, sourceAddress := range addresses {
|
for _, sourceAddress := range addresses {
|
||||||
builder.macToID[sourceAddress] = sourceId
|
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 {
|
type Node struct {
|
||||||
Firstseen jsontime.Time `json:"firstseen"`
|
Firstseen jsontime.Time `json:"firstseen"`
|
||||||
Lastseen jsontime.Time `json:"lastseen"`
|
Lastseen jsontime.Time `json:"lastseen"`
|
||||||
|
Flags *Flags `json:"flags,omitempty"`
|
||||||
|
//Statistics *MeshviewerStatistics `json:"statistics"`
|
||||||
Statistics *data.Statistics `json:"statistics"`
|
Statistics *data.Statistics `json:"statistics"`
|
||||||
Nodeinfo *data.NodeInfo `json:"nodeinfo"`
|
Nodeinfo *data.NodeInfo `json:"nodeinfo"`
|
||||||
Neighbours *data.Neighbours `json:"-"`
|
Neighbours *data.Neighbours `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type NodeElement struct {
|
type Flags struct {
|
||||||
NodeId string
|
Online bool `json:"online"`
|
||||||
|
Gateway bool `json:"gateway"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nodes struct: cache DB of Node's structs
|
// Nodes struct: cache DB of Node's structs
|
||||||
@ -60,6 +63,10 @@ func (nodes *Nodes) Update(nodeID string, res *data.ResponseData) {
|
|||||||
if node == nil {
|
if node == nil {
|
||||||
node = &Node{
|
node = &Node{
|
||||||
Firstseen: now,
|
Firstseen: now,
|
||||||
|
Flags: &Flags{
|
||||||
|
Online: true,
|
||||||
|
Gateway: false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
nodes.List[nodeID] = node
|
nodes.List[nodeID] = node
|
||||||
}
|
}
|
||||||
@ -75,11 +82,27 @@ func (nodes *Nodes) Update(nodeID string, res *data.ResponseData) {
|
|||||||
// Update nodeinfo
|
// Update nodeinfo
|
||||||
if val := res.NodeInfo; val != nil {
|
if val := res.NodeInfo; val != nil {
|
||||||
node.Nodeinfo = val
|
node.Nodeinfo = val
|
||||||
|
node.Flags.Gateway = val.VPN
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update statistics
|
// Update statistics
|
||||||
if val := res.Statistics; val != nil {
|
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.Timestamp = jsontime.Now()
|
||||||
nodes.Lock()
|
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
|
// serialize nodes
|
||||||
save(nodes, nodes.config.Nodes.NodesPath)
|
save(nodes, nodes.config.Nodes.NodesPath)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user