Skip to content

Commit 0c7e846

Browse files
committed
Update.
1 parent 3d7f4de commit 0c7e846

File tree

9 files changed

+79
-212
lines changed

9 files changed

+79
-212
lines changed

model/config.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ var Languages = map[string]string{
1818
}
1919

2020
var Themes = map[string]string{
21-
"default": "Default",
22-
"custom": "Custom(local)",
21+
"default": "Default",
22+
"custom": "Custom(local)",
2323
}
2424

2525
var DashboardThemes = map[string]string{
@@ -130,10 +130,10 @@ func (c *Config) Read(path string) error {
130130
}
131131

132132
if c.Site.Brand == "" {
133-
c.Site.Brand = "Nezha Monitoring"
133+
c.Site.Brand = "ServerStatus"
134134
}
135135
if c.Site.CookieName == "" {
136-
c.Site.CookieName = "nezha-dashboard"
136+
c.Site.CookieName = "server-dash"
137137
}
138138
if c.Site.Theme == "" {
139139
c.Site.Theme = "default"

resource/static/main.js

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ function addOrEditDDNS(ddns) {
279279
const modal = $(".ddns.modal");
280280
modal.children(".header").text((ddns ? LANG.Edit : LANG.Add));
281281
modal
282-
.find(".nezha-primary-btn.button")
282+
.find(".server-primary-btn.button")
283283
.html(
284284
ddns
285285
? LANG.Edit + '<i class="edit icon"></i>'
@@ -328,7 +328,7 @@ function addOrEditNAT(nat) {
328328
const modal = $(".nat.modal");
329329
modal.children(".header").text((nat ? LANG.Edit : LANG.Add));
330330
modal
331-
.find(".nezha-primary-btn.button")
331+
.find(".server-primary-btn.button")
332332
.html(
333333
nat
334334
? LANG.Edit + '<i class="edit icon"></i>'
@@ -751,68 +751,46 @@ function fetchTrafficData(serverId) {
751751
function debugOfflineServersConfig() {
752752
// 检查全局状态数据是否存在
753753
if (!window.statusCards || !window.statusCards.servers) {
754-
console.log("状态数据尚未加载,稍后再试");
755754
return;
756755
}
757756

758757
// 遍历所有服务器,检查并修复离线服务器的配置数据
759758
window.statusCards.servers.forEach(server => {
760-
// 重点关注ID为39的服务器
761-
const isTargetServer = server.ID === 39;
762-
763759
if (!server.IsOnline) {
764-
if (isTargetServer) {
765-
console.log(`服务器: ${server.Name} (ID: ${server.ID})`, server);
766-
console.log("Host 配置信息:", server.Host);
767-
}
768-
769760
// 确保Host对象存在
770761
if (!server.Host) {
771762
server.Host = {};
772-
if (isTargetServer) console.log("创建空Host对象");
773763
}
774764

775765
// 确保CPU数组存在且不为null
776766
if (!server.Host.CPU || !Array.isArray(server.Host.CPU)) {
777767
server.Host.CPU = [];
778-
if (isTargetServer) console.log("CPU信息为空");
779768
}
780769

781770
// 确保GPU数组存在且不为null
782771
if (!server.Host.GPU || !Array.isArray(server.Host.GPU)) {
783772
server.Host.GPU = [];
784-
if (isTargetServer) console.log("GPU信息为空");
785773
}
786774

787775
// 确保其他必要的属性存在
788776
if (!server.Host.MemTotal) {
789777
server.Host.MemTotal = 0;
790-
if (isTargetServer) console.log("内存信息为空");
791778
}
792779

793780
if (!server.Host.Platform) {
794781
server.Host.Platform = "";
795-
if (isTargetServer) console.log("平台信息为空");
796782
}
797783

798784
if (!server.Host.PlatformVersion) {
799785
server.Host.PlatformVersion = "";
800-
if (isTargetServer) console.log("平台版本信息为空");
801786
}
802787

803788
if (!server.Host.Virtualization) {
804789
server.Host.Virtualization = "";
805-
if (isTargetServer) console.log("虚拟化信息为空");
806790
}
807791

808792
if (!server.Host.Arch) {
809793
server.Host.Arch = "";
810-
if (isTargetServer) console.log("架构信息为空");
811-
}
812-
813-
// 更新原始对象,确保Vue能检测到变化
814-
if (isTargetServer) {
815-
console.log("修复后的Host对象:", server.Host);
816794
}
817795
}
818796
});

resource/template/component/ddns.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
</div>
5858
<div class="field">
5959
<label>{{tr "WebhookHeaders"}}</label>
60-
<textarea name="WebhookHeaders" placeholder='{"User-Agent":"Nezha-Agent"}'></textarea>
60+
<textarea name="WebhookHeaders" placeholder='{"User-Agent":"ServerStatus"}'></textarea>
6161
</div>
6262
<div class="field">
6363
<label>{{tr "WebhookRequestBody"}}</label>
@@ -79,7 +79,7 @@
7979
</div>
8080
<div class="actions">
8181
<div class="ui negative button">{{tr "Cancel"}}</div>
82-
<button class="ui positive nezha-primary-btn right labeled icon button">{{tr "Confirm"}}<i class="checkmark icon"></i>
82+
<button class="ui positive server-primary-btn right labeled icon button">{{tr "Confirm"}}<i class="checkmark icon"></i>
8383
</button>
8484
</div>
8585
</div>

resource/template/dashboard-default/ddns.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<div class="ui container">
66
<div class="ui grid">
77
<div class="right floated right aligned twelve wide column">
8-
<button class="ui right labeled nezha-primary-btn icon button" onclick="addOrEditDDNS()"><i
8+
<button class="ui right labeled server-primary-btn icon button" onclick="addOrEditDDNS()"><i
99
class="add icon"></i> {{tr "AddDDNSProfile"}}
1010
</button>
1111
</div>

resource/template/dashboard-default/file.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
</mdui-dialog>
8484

8585
<script>
86-
let currentPath = '/opt/nezha/';
86+
let currentPath = '/opt/serverstatus/';
8787
let fileName = '';
8888
let receivedBuffer = []; // 用于缓存数据块
8989
let expectedLength = 0;

service/rpc/server.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func (s *ServerHandler) ReportSystemState(c context.Context, r *pb.State) (*pb.R
158158
}
159159
}
160160
} else {
161-
log.Printf("NG>> 序列化服务器 %s 的最后状态失败: %v", singleton.ServerList[clientID].Name, err)
161+
log.Printf("序列化服务器 %s 的最后状态失败: %v", singleton.ServerList[clientID].Name, err)
162162
}
163163

164164
// 确保PrevTransferSnapshot值被正确初始化
@@ -193,7 +193,7 @@ func (s *ServerHandler) ReportSystemInfo(c context.Context, r *pb.Host) (*pb.Rec
193193
}(provider)
194194
}
195195
} else {
196-
log.Printf("NG>> 获取DDNS配置时发生错误: %v", err)
196+
log.Printf("获取DDNS配置时发生错误: %v", err)
197197
}
198198
}
199199

@@ -223,7 +223,7 @@ func (s *ServerHandler) ReportSystemInfo(c context.Context, r *pb.Host) (*pb.Rec
223223
* 这是可以借助上报顺序的空档,标记服务器为重启状态,表示从该节点开始累计流量
224224
*/
225225
if singleton.ServerList[clientID].Host != nil && singleton.ServerList[clientID].Host.BootTime < host.BootTime {
226-
log.Printf("NG>> 检测到服务器 %s 重启,重置流量计数", singleton.ServerList[clientID].Name)
226+
log.Printf("检测到服务器 %s 重启,重置流量计数", singleton.ServerList[clientID].Name)
227227

228228
// 服务器重启时保持累计流量不变,只重置上次记录点
229229
singleton.ServerList[clientID].PrevTransferInSnapshot = 0
@@ -241,13 +241,10 @@ func (s *ServerHandler) ReportSystemInfo(c context.Context, r *pb.Host) (*pb.Rec
241241
// 更新servers表中的host_json字段
242242
if err := singleton.DB.Exec("UPDATE servers SET host_json = ? WHERE id = ?",
243243
string(hostJSON), clientID).Error; err != nil {
244-
log.Printf("NG>> [RPC] 保存服务器ID:%d (%s) 的Host配置失败: %v", clientID, singleton.ServerList[clientID].Name, err)
245-
} else if singleton.Conf.Debug {
246-
log.Printf("NG>> [RPC] 保存服务器ID:%d (%s) 的Host配置成功, CPU=%v",
247-
clientID, singleton.ServerList[clientID].Name, len(host.CPU) > 0)
244+
log.Printf("保存服务器ID:%d (%s) 的Host配置失败: %v", clientID, singleton.ServerList[clientID].Name, err)
248245
}
249246
} else {
250-
log.Printf("NG>> 序列化服务器 %s 的Host信息失败: %v", singleton.ServerList[clientID].Name, err)
247+
log.Printf("序列化服务器 %s 的Host信息失败: %v", singleton.ServerList[clientID].Name, err)
251248
}
252249

253250
singleton.ServerList[clientID].Host = &host

service/singleton/api.go

Lines changed: 26 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -115,50 +115,38 @@ func (s *ServerAPIService) GetStatusByIDList(idList []uint64) *ServerStatusRespo
115115
continue
116116
}
117117

118-
// 尝试从数据库加载Host信息
118+
// 获取Host信息,优先使用内存中的数据
119119
host := server.Host
120-
if host == nil || host.MemTotal == 0 || len(host.CPU) == 0 {
120+
if host == nil || (host.MemTotal == 0 && len(host.CPU) == 0) {
121+
// 尝试从数据库重新加载Host信息
121122
var hostJSON []byte
122123
if err := DB.Raw("SELECT host_json FROM servers WHERE id = ?", server.ID).Scan(&hostJSON).Error; err == nil && len(hostJSON) > 0 {
123-
tempHost := &model.Host{
124-
CPU: []string{},
125-
GPU: []string{},
126-
}
124+
tempHost := &model.Host{}
127125
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-
133-
// 不再填充默认数据,只使用实际数据
134-
if Conf.Debug {
135-
log.Printf("NG>> API - 服务器 %s (ID: %d) 成功加载Host数据", server.Name, server.ID)
136-
}
126+
tempHost.Initialize()
137127
host = tempHost
138128
server.Host = tempHost // 更新内存中的数据
139-
} else if Conf.Debug {
140-
log.Printf("NG>> API - 服务器 %s (ID: %d) 解析Host数据失败: %v", server.Name, server.ID, err)
129+
} else {
130+
log.Printf("API - 服务器 %s (ID: %d) 解析Host数据失败: %v", server.Name, server.ID, err)
141131
}
142132
}
143133
}
144134

145-
// 获取状态数据,优先使用当前状态,没有则使用离线前保存的最后状态
146-
state := server.State
147-
if state == nil && server.LastStateBeforeOffline != nil {
148-
state = server.LastStateBeforeOffline
149-
}
150-
151-
// 如果没有有效的Host或状态数据,跳过该服务器
135+
// 如果仍然没有有效的Host数据,创建空的Host对象
152136
if host == nil {
153-
// 确保至少有一个空的Host对象,避免前端报错
154137
host = &model.Host{}
155-
// 确保初始化数组
156138
host.Initialize()
157139
} else {
158140
// 确保已有的Host对象数组已初始化
159141
host.Initialize()
160142
}
161143

144+
// 获取状态数据,优先使用当前状态,没有则使用离线前保存的最后状态
145+
state := server.State
146+
if state == nil && server.LastStateBeforeOffline != nil {
147+
state = server.LastStateBeforeOffline
148+
}
149+
162150
ipv4, ipv6, validIP := utils.SplitIPAddr(host.IP)
163151
info := CommonServerInfo{
164152
ID: server.ID,
@@ -201,36 +189,30 @@ func (s *ServerAPIService) GetAllStatus() *ServerStatusResponse {
201189
defer ServerLock.RUnlock()
202190

203191
for _, v := range ServerList {
204-
// 尝试从数据库加载Host信息
192+
// 获取Host信息,优先使用内存中的数据
205193
host := v.Host
206-
if host == nil || host.MemTotal == 0 || len(host.CPU) == 0 {
194+
if host == nil || (host.MemTotal == 0 && len(host.CPU) == 0) {
195+
// 尝试从数据库重新加载Host信息
207196
var hostJSON []byte
208197
if err := DB.Raw("SELECT host_json FROM servers WHERE id = ?", v.ID).Scan(&hostJSON).Error; err == nil && len(hostJSON) > 0 {
209-
tempHost := &model.Host{
210-
CPU: []string{},
211-
GPU: []string{},
212-
}
198+
tempHost := &model.Host{}
213199
if err := utils.Json.Unmarshal(hostJSON, tempHost); err == nil {
214-
// 仅为特定问题服务器添加日志(ID为39)
215-
if v.ID == 39 {
216-
log.Printf("NG>> [API] 离线服务器ID:39 (%s) Host数据: %s", v.Name, string(hostJSON))
217-
}
218-
219-
// 不再填充默认数据,只使用实际数据
220-
if Conf.Debug {
221-
log.Printf("NG>> API - 服务器 %s (ID: %d) 成功加载Host数据", v.Name, v.ID)
222-
}
200+
tempHost.Initialize()
223201
host = tempHost
224202
v.Host = tempHost // 更新内存中的数据
225-
} else if Conf.Debug {
226-
log.Printf("NG>> API - 服务器 %s (ID: %d) 解析Host数据失败: %v", v.Name, v.ID, err)
203+
} else {
204+
log.Printf("API - 服务器 %s (ID: %d) 解析Host数据失败: %v", v.Name, v.ID, err)
227205
}
228206
}
229207
}
230208

231-
// 如果Host信息不可用,创建一个空对象而不是跳过
209+
// 如果仍然没有有效的Host数据,创建空的Host对象
232210
if host == nil {
233211
host = &model.Host{}
212+
host.Initialize()
213+
} else {
214+
// 确保已有的Host对象数组已初始化
215+
host.Initialize()
234216
}
235217

236218
// 获取状态数据,优先使用当前状态,没有则使用离线前保存的最后状态
@@ -239,17 +221,6 @@ func (s *ServerAPIService) GetAllStatus() *ServerStatusResponse {
239221
state = v.LastStateBeforeOffline
240222
}
241223

242-
// 如果没有有效的Host或状态数据,跳过该服务器
243-
if host == nil {
244-
// 确保至少有一个空的Host对象,避免前端报错
245-
host = &model.Host{}
246-
// 确保初始化数组
247-
host.Initialize()
248-
} else {
249-
// 确保已有的Host对象数组已初始化
250-
host.Initialize()
251-
}
252-
253224
ipv4, ipv6, validIP := utils.SplitIPAddr(host.IP)
254225
info := CommonServerInfo{
255226
ID: v.ID,

0 commit comments

Comments
 (0)