@@ -44,16 +44,17 @@ func loadServers() {
4444 var hostJSON []byte
4545 if err := DB .Raw ("SELECT host_json FROM last_reported_host WHERE server_id = ?" , innerS .ID ).Scan (& hostJSON ).Error ; err == nil && len (hostJSON ) > 0 {
4646 if err := utils .Json .Unmarshal (hostJSON , innerS .Host ); err != nil {
47- log .Printf ("NG>> 解析服务器 %s 的Host数据失败: %v" , innerS .Name , err )
48- } else if Conf .Debug {
49- log .Printf ("NG>> 服务器 %s 成功加载Host数据: CPU=%v, MemTotal=%v" ,
50- innerS .Name , len (innerS .Host .CPU ) > 0 , innerS .Host .MemTotal > 0 )
47+ log .Printf ("警告: 解析服务器 %s 的Host数据失败: %v" , innerS .Name , err )
48+ } else {
49+ // 记录Host数据不完整的情况,但不添加假数据
50+ if len (innerS .Host .CPU ) == 0 || innerS .Host .MemTotal == 0 {
51+ log .Printf ("警告: 服务器 %s 的Host数据不完整: CPU=%v, MemTotal=%v, Platform=%v" ,
52+ innerS .Name , len (innerS .Host .CPU ) > 0 , innerS .Host .MemTotal > 0 , innerS .Host .Platform != "" )
53+ }
5154 }
52- } else if Conf . Debug {
55+ } else {
5356 if err != nil {
54- log .Printf ("NG>> 服务器 %s 从数据库加载Host数据失败: %v" , innerS .Name , err )
55- } else {
56- log .Printf ("NG>> 服务器 %s 的Host数据在数据库中不存在或为空" , innerS .Name )
57+ log .Printf ("警告: 服务器 %s 从数据库加载Host数据失败: %v" , innerS .Name , err )
5758 }
5859 }
5960
@@ -101,11 +102,6 @@ func loadServers() {
101102 ServerTagToIDList [innerS .Tag ] = append (ServerTagToIDList [innerS .Tag ], innerS .ID )
102103 }
103104 ReSortServer ()
104-
105- // 仅在Debug模式下输出详细信息
106- if Conf .Debug {
107- printServerLoadSummary ()
108- }
109105}
110106
111107// ReSortServer 根据服务器ID 对服务器列表进行排序(ID越大越靠前)
@@ -138,20 +134,30 @@ func ReSortServer() {
138134 }
139135 return SortedServerListForGuest [i ].DisplayIndex > SortedServerListForGuest [j ].DisplayIndex
140136 })
137+
138+ // 总是执行,不再限制在Debug模式下
139+ printServerLoadSummary ()
141140}
142141
143142// printServerLoadSummary 输出服务器状态加载情况的摘要信息
144143func printServerLoadSummary () {
145- log .Println ("NG>> 服务器状态加载情况:" )
146-
147144 // 统计信息
148145 loaded := 0
149146 withState := 0
150147 withHost := 0
148+ incompleteHost := 0
149+ noHost := 0
151150
152151 for _ , server := range ServerList {
153- if server .Host != nil && server .Host .MemTotal > 0 {
154- withHost ++
152+ if server .Host != nil {
153+ if server .Host .MemTotal > 0 && len (server .Host .CPU ) > 0 {
154+ withHost ++
155+ } else {
156+ incompleteHost ++
157+ // 仅记录不完整的Host对象,但不输出详细信息
158+ }
159+ } else {
160+ noHost ++
155161 }
156162
157163 if server .State != nil &&
@@ -166,6 +172,7 @@ func printServerLoadSummary() {
166172 }
167173 }
168174
169- log .Printf ("NG>> 总共加载了 %d 台服务器: 有Host信息=%d, 有State信息=%d, 有离线前状态=%d" ,
170- len (ServerList ), withHost , withState , loaded )
175+ // 只输出一次总体摘要
176+ log .Printf ("警告: 服务器状态统计 - 总计=%d, 有完整Host=%d, Host不完整=%d, 无Host=%d, 有State=%d, 有离线前状态=%d" ,
177+ len (ServerList ), withHost , incompleteHost , noHost , withState , loaded )
171178}
0 commit comments