Skip to content

Commit e39104f

Browse files
committed
Update.
1 parent 1095e70 commit e39104f

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

service/rpc/server.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,17 @@ func (s *ServerHandler) ReportSystemInfo(c context.Context, r *pb.Host) (*pb.Rec
244244
hostJSON, err := utils.Json.Marshal(host)
245245
if err == nil {
246246
// 使用Replace语法,如果记录不存在则插入,存在则更新
247-
singleton.DB.Exec(`
247+
if err := singleton.DB.Exec(`
248248
INSERT INTO last_reported_host (server_id, host_json)
249249
VALUES (?, ?)
250250
ON CONFLICT(server_id)
251251
DO UPDATE SET host_json = ?
252-
`, clientID, string(hostJSON), string(hostJSON))
252+
`, clientID, string(hostJSON), string(hostJSON)).Error; err != nil {
253+
log.Printf("NG>> [RPC] 保存服务器ID:%d (%s) 的Host配置失败: %v", clientID, singleton.ServerList[clientID].Name, err)
254+
} else if singleton.Conf.Debug {
255+
log.Printf("NG>> [RPC] 保存服务器ID:%d (%s) 的Host配置成功, CPU=%v",
256+
clientID, singleton.ServerList[clientID].Name, len(host.CPU) > 0)
257+
}
253258
} else {
254259
log.Printf("NG>> 序列化服务器 %s 的Host信息失败: %v", singleton.ServerList[clientID].Name, err)
255260
}

service/singleton/api.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ func (s *ServerAPIService) GetStatusByIDList(idList []uint64) *ServerStatusRespo
125125
GPU: []string{},
126126
}
127127
if err := utils.Json.Unmarshal(hostJSON, tempHost); err == nil {
128+
// 仅为特定问题服务器添加日志(ID为39)
129+
if server.ID == 39 {
130+
log.Printf("NG>> [API] 离线服务器ID:39 (%s) Host数据: %s", server.Name, string(hostJSON))
131+
}
132+
128133
// 不再填充默认数据,只使用实际数据
129134
if Conf.Debug {
130135
log.Printf("NG>> API - 服务器 %s (ID: %d) 成功加载Host数据", server.Name, server.ID)
@@ -201,6 +206,11 @@ func (s *ServerAPIService) GetAllStatus() *ServerStatusResponse {
201206
GPU: []string{},
202207
}
203208
if err := utils.Json.Unmarshal(hostJSON, tempHost); err == nil {
209+
// 仅为特定问题服务器添加日志(ID为39)
210+
if v.ID == 39 {
211+
log.Printf("NG>> [API] 离线服务器ID:39 (%s) Host数据: %s", v.Name, string(hostJSON))
212+
}
213+
204214
// 不再填充默认数据,只使用实际数据
205215
if Conf.Debug {
206216
log.Printf("NG>> API - 服务器 %s (ID: %d) 成功加载Host数据", v.Name, v.ID)

service/singleton/server.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,24 @@ func loadServers() {
4747
// 从数据库加载最后一次上报的Host信息
4848
var hostJSON []byte
4949
if err := DB.Raw("SELECT host_json FROM last_reported_host WHERE server_id = ?", innerS.ID).Scan(&hostJSON).Error; err == nil && len(hostJSON) > 0 {
50-
if Conf.Debug {
50+
// 只记录特定离线服务器的信息(ID为39)
51+
if innerS.ID == 39 {
52+
log.Printf("NG>> [服务启动] 离线服务器ID:39 (%s) 加载Host数据: %s",
53+
innerS.Name, string(hostJSON))
54+
} else if Conf.Debug {
5155
log.Printf("NG>> 服务器 %s (ID: %d) 加载Host数据: %d字节", innerS.Name, innerS.ID, len(hostJSON))
5256
}
57+
5358
if err := utils.Json.Unmarshal(hostJSON, innerS.Host); err != nil {
5459
log.Printf("NG>> 解析服务器 %s 的Host数据失败: %v", innerS.Name, err)
55-
} else if Conf.Debug {
56-
// 记录Host数据不完整的情况,但不添加假数据
57-
if len(innerS.Host.CPU) == 0 || innerS.Host.MemTotal == 0 {
58-
log.Printf("NG>> 服务器 %s 的Host数据不完整: CPU=%v, MemTotal=%v, Platform=%v",
59-
innerS.Name, len(innerS.Host.CPU) > 0, innerS.Host.MemTotal > 0, innerS.Host.Platform != "")
60-
}
61-
}
62-
} else {
63-
if err != nil && Conf.Debug {
64-
log.Printf("NG>> 服务器 %s 从数据库加载Host数据失败: %v", innerS.Name, err)
60+
} else if innerS.ID == 39 {
61+
// 只记录特定离线服务器的信息
62+
log.Printf("NG>> [服务启动] 离线服务器ID:39 (%s) 解析后数据: CPU=%v, MEM=%v",
63+
innerS.Name, innerS.Host.CPU, innerS.Host.MemTotal)
6564
}
65+
} else if err != nil && innerS.ID == 39 {
66+
// 只记录特定离线服务器的错误
67+
log.Printf("NG>> 服务器 %s (ID: %d) 从数据库加载Host数据失败: %v", innerS.Name, innerS.ID, err)
6668
}
6769

6870
// 加载离线前的最后状态

0 commit comments

Comments
 (0)