mirror of
https://github.com/nezhahq/nezha.git
synced 2025-01-22 12:48:14 -05:00
chore: refactor
Some checks are pending
CodeQL / Analyze (go) (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
Contributors / contributors (push) Waiting to run
Sync / sync-to-jihulab (push) Waiting to run
Run Tests / tests (macos) (push) Waiting to run
Run Tests / tests (ubuntu) (push) Waiting to run
Run Tests / tests (windows) (push) Waiting to run
Some checks are pending
CodeQL / Analyze (go) (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
Contributors / contributors (push) Waiting to run
Sync / sync-to-jihulab (push) Waiting to run
Run Tests / tests (macos) (push) Waiting to run
Run Tests / tests (ubuntu) (push) Waiting to run
Run Tests / tests (windows) (push) Waiting to run
This commit is contained in:
parent
81a08a38da
commit
3999d1f99a
@ -160,15 +160,13 @@ func listServerWithServices(c *gin.Context) ([]uint64, error) {
|
|||||||
for _, id := range serverIdsWithService {
|
for _, id := range serverIdsWithService {
|
||||||
singleton.ServerLock.RLock()
|
singleton.ServerLock.RLock()
|
||||||
server, ok := singleton.ServerList[id]
|
server, ok := singleton.ServerList[id]
|
||||||
if !ok {
|
singleton.ServerLock.RUnlock()
|
||||||
singleton.ServerLock.RUnlock()
|
if !ok || server == nil {
|
||||||
return nil, singleton.Localizer.ErrorT("server not found")
|
return nil, singleton.Localizer.ErrorT("server not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !server.HideForGuest || authorized {
|
if !server.HideForGuest || authorized {
|
||||||
ret = append(ret, id)
|
ret = append(ret, id)
|
||||||
}
|
}
|
||||||
singleton.ServerLock.RUnlock()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret, nil
|
return ret, nil
|
||||||
|
@ -75,6 +75,7 @@ func (a *authHandler) Check(ctx context.Context) (uint64, error) {
|
|||||||
singleton.ServerList[s.ID] = &s
|
singleton.ServerList[s.ID] = &s
|
||||||
singleton.ServerUUIDToID[clientUUID] = s.ID
|
singleton.ServerUUIDToID[clientUUID] = s.ID
|
||||||
singleton.ServerLock.Unlock()
|
singleton.ServerLock.Unlock()
|
||||||
|
|
||||||
singleton.ReSortServer()
|
singleton.ReSortServer()
|
||||||
|
|
||||||
clientID = s.ID
|
clientID = s.ID
|
||||||
|
@ -133,17 +133,22 @@ func (s *NezhaHandler) onReportSystemInfo(c context.Context, r *pb.Host) error {
|
|||||||
singleton.ServerLock.RLock()
|
singleton.ServerLock.RLock()
|
||||||
defer singleton.ServerLock.RUnlock()
|
defer singleton.ServerLock.RUnlock()
|
||||||
|
|
||||||
|
server, ok := singleton.ServerList[clientID]
|
||||||
|
if !ok || server == nil {
|
||||||
|
return fmt.Errorf("server not found")
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 这里的 singleton 中的数据都是关机前的旧数据
|
* 这里的 singleton 中的数据都是关机前的旧数据
|
||||||
* 当 agent 重启时,bootTime 变大,agent 端会先上报 host 信息,然后上报 state 信息
|
* 当 agent 重启时,bootTime 变大,agent 端会先上报 host 信息,然后上报 state 信息
|
||||||
* 这是可以借助上报顺序的空档,将停机前的流量统计数据标记下来,加到下一个小时的数据点上
|
* 这是可以借助上报顺序的空档,将停机前的流量统计数据标记下来,加到下一个小时的数据点上
|
||||||
*/
|
*/
|
||||||
if singleton.ServerList[clientID].Host != nil && singleton.ServerList[clientID].Host.BootTime < host.BootTime {
|
if server.Host != nil && server.Host.BootTime < host.BootTime {
|
||||||
singleton.ServerList[clientID].PrevTransferInSnapshot = singleton.ServerList[clientID].PrevTransferInSnapshot - int64(singleton.ServerList[clientID].State.NetInTransfer)
|
server.PrevTransferInSnapshot = server.PrevTransferInSnapshot - int64(server.State.NetInTransfer)
|
||||||
singleton.ServerList[clientID].PrevTransferOutSnapshot = singleton.ServerList[clientID].PrevTransferOutSnapshot - int64(singleton.ServerList[clientID].State.NetOutTransfer)
|
server.PrevTransferOutSnapshot = server.PrevTransferOutSnapshot - int64(server.State.NetOutTransfer)
|
||||||
}
|
}
|
||||||
|
|
||||||
singleton.ServerList[clientID].Host = &host
|
server.Host = &host
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user