diff --git a/cmd/dashboard/controller/service.go b/cmd/dashboard/controller/service.go index 2a3022c..a5f8b2e 100644 --- a/cmd/dashboard/controller/service.go +++ b/cmd/dashboard/controller/service.go @@ -160,15 +160,13 @@ func listServerWithServices(c *gin.Context) ([]uint64, error) { for _, id := range serverIdsWithService { singleton.ServerLock.RLock() 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") } - if !server.HideForGuest || authorized { ret = append(ret, id) } - singleton.ServerLock.RUnlock() } return ret, nil diff --git a/service/rpc/auth.go b/service/rpc/auth.go index fa601dd..a99949b 100644 --- a/service/rpc/auth.go +++ b/service/rpc/auth.go @@ -75,6 +75,7 @@ func (a *authHandler) Check(ctx context.Context) (uint64, error) { singleton.ServerList[s.ID] = &s singleton.ServerUUIDToID[clientUUID] = s.ID singleton.ServerLock.Unlock() + singleton.ReSortServer() clientID = s.ID diff --git a/service/rpc/nezha.go b/service/rpc/nezha.go index ba49661..98996fb 100644 --- a/service/rpc/nezha.go +++ b/service/rpc/nezha.go @@ -133,17 +133,22 @@ func (s *NezhaHandler) onReportSystemInfo(c context.Context, r *pb.Host) error { singleton.ServerLock.RLock() defer singleton.ServerLock.RUnlock() + server, ok := singleton.ServerList[clientID] + if !ok || server == nil { + return fmt.Errorf("server not found") + } + /** * 这里的 singleton 中的数据都是关机前的旧数据 * 当 agent 重启时,bootTime 变大,agent 端会先上报 host 信息,然后上报 state 信息 * 这是可以借助上报顺序的空档,将停机前的流量统计数据标记下来,加到下一个小时的数据点上 */ - if singleton.ServerList[clientID].Host != nil && singleton.ServerList[clientID].Host.BootTime < host.BootTime { - singleton.ServerList[clientID].PrevTransferInSnapshot = singleton.ServerList[clientID].PrevTransferInSnapshot - int64(singleton.ServerList[clientID].State.NetInTransfer) - singleton.ServerList[clientID].PrevTransferOutSnapshot = singleton.ServerList[clientID].PrevTransferOutSnapshot - int64(singleton.ServerList[clientID].State.NetOutTransfer) + if server.Host != nil && server.Host.BootTime < host.BootTime { + server.PrevTransferInSnapshot = server.PrevTransferInSnapshot - int64(server.State.NetInTransfer) + server.PrevTransferOutSnapshot = server.PrevTransferOutSnapshot - int64(server.State.NetOutTransfer) } - singleton.ServerList[clientID].Host = &host + server.Host = &host return nil }