update nodes
This commit is contained in:
parent
67c6031fff
commit
fb2f0bda27
@ -27,7 +27,7 @@ type Nodes struct {
|
|||||||
Version int `json:"version"`
|
Version int `json:"version"`
|
||||||
Timestamp jsontime.Time `json:"timestamp"`
|
Timestamp jsontime.Time `json:"timestamp"`
|
||||||
List map[string]*Node `json:"nodes"` // the current nodemap, indexed by node ID
|
List map[string]*Node `json:"nodes"` // the current nodemap, indexed by node ID
|
||||||
sync.Mutex
|
sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
type Statistics struct {
|
type Statistics struct {
|
||||||
|
@ -29,7 +29,7 @@ type Nodes struct {
|
|||||||
Timestamp jsontime.Time `json:"timestamp"`
|
Timestamp jsontime.Time `json:"timestamp"`
|
||||||
List map[string]*Node `json:"nodes"` // the current nodemap, indexed by node ID
|
List map[string]*Node `json:"nodes"` // the current nodemap, indexed by node ID
|
||||||
config *Config
|
config *Config
|
||||||
sync.Mutex
|
sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewNodes create Nodes structs
|
// NewNodes create Nodes structs
|
||||||
@ -89,38 +89,40 @@ func (nodes *Nodes) Update(nodeID string, res *data.ResponseData) {
|
|||||||
node.Statistics = val
|
node.Statistics = val
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetNodesMini get meshviewer valide JSON
|
||||||
func (nodes *Nodes) GetNodesMini() *meshviewer.Nodes {
|
func (nodes *Nodes) GetNodesMini() *meshviewer.Nodes {
|
||||||
meshviewerNodes := &meshviewer.Nodes{
|
meshviewerNodes := &meshviewer.Nodes{
|
||||||
Version: 1,
|
Version: 1,
|
||||||
List: make(map[string]*meshviewer.Node),
|
List: make(map[string]*meshviewer.Node),
|
||||||
Timestamp: nodes.Timestamp,
|
Timestamp: nodes.Timestamp,
|
||||||
}
|
}
|
||||||
for nodeID, _ := range nodes.List {
|
for nodeID := range nodes.List {
|
||||||
meshviewerNodes.Lock()
|
|
||||||
node, _ := meshviewerNodes.List[nodeID]
|
|
||||||
|
|
||||||
|
node, _ := meshviewerNodes.List[nodeID]
|
||||||
|
nodeOrigin := nodes.List[nodeID]
|
||||||
if node == nil {
|
if node == nil {
|
||||||
node = &meshviewer.Node{
|
node = &meshviewer.Node{
|
||||||
Firstseen: nodes.List[nodeID].Firstseen,
|
Firstseen: nodeOrigin.Firstseen,
|
||||||
Lastseen: nodes.List[nodeID].Lastseen,
|
Lastseen: nodeOrigin.Lastseen,
|
||||||
Flags: nodes.List[nodeID].Flags,
|
Flags: nodeOrigin.Flags,
|
||||||
Nodeinfo: nodes.List[nodeID].Nodeinfo,
|
Nodeinfo: nodeOrigin.Nodeinfo,
|
||||||
}
|
}
|
||||||
meshviewerNodes.List[nodeID] = node
|
meshviewerNodes.List[nodeID] = node
|
||||||
}
|
}
|
||||||
meshviewerNodes.Unlock()
|
|
||||||
node.Statistics = &meshviewer.Statistics{
|
node.Statistics = &meshviewer.Statistics{
|
||||||
NodeId: nodes.List[nodeID].Statistics.NodeId,
|
NodeId: nodeOrigin.Statistics.NodeId,
|
||||||
Clients: nodes.List[nodeID].Statistics.Clients.Total,
|
Clients: nodeOrigin.Statistics.Clients.Total,
|
||||||
Gateway: nodes.List[nodeID].Statistics.Gateway,
|
Gateway: nodeOrigin.Statistics.Gateway,
|
||||||
RootFsUsage: nodes.List[nodeID].Statistics.RootFsUsage,
|
RootFsUsage: nodeOrigin.Statistics.RootFsUsage,
|
||||||
LoadAverage: nodes.List[nodeID].Statistics.LoadAverage,
|
LoadAverage: nodeOrigin.Statistics.LoadAverage,
|
||||||
Memory: nodes.List[nodeID].Statistics.Memory,
|
Memory: nodeOrigin.Statistics.Memory,
|
||||||
Uptime: nodes.List[nodeID].Statistics.Uptime,
|
Uptime: nodeOrigin.Statistics.Uptime,
|
||||||
Idletime: nodes.List[nodeID].Statistics.Idletime,
|
Idletime: nodeOrigin.Statistics.Idletime,
|
||||||
Processes: nodes.List[nodeID].Statistics.Processes,
|
Processes: nodeOrigin.Statistics.Processes,
|
||||||
MeshVpn: nodes.List[nodeID].Statistics.MeshVpn,
|
MeshVpn: nodeOrigin.Statistics.MeshVpn,
|
||||||
Traffic: nodes.List[nodeID].Statistics.Traffic,
|
Traffic: nodeOrigin.Statistics.Traffic,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return meshviewerNodes
|
return meshviewerNodes
|
||||||
@ -160,7 +162,7 @@ func (nodes *Nodes) load() {
|
|||||||
log.Println("loading", path)
|
log.Println("loading", path)
|
||||||
|
|
||||||
if filedata, err := ioutil.ReadFile(path); err == nil {
|
if filedata, err := ioutil.ReadFile(path); err == nil {
|
||||||
if err := json.Unmarshal(filedata, nodes); err == nil {
|
if err = json.Unmarshal(filedata, nodes); err == nil {
|
||||||
log.Println("loaded", len(nodes.List), "nodes")
|
log.Println("loaded", len(nodes.List), "nodes")
|
||||||
} else {
|
} else {
|
||||||
log.Println("failed to unmarshal nodes:", err)
|
log.Println("failed to unmarshal nodes:", err)
|
||||||
|
Loading…
Reference in New Issue
Block a user