Skip to content

Commit 9f791f1

Browse files
committed
Update.
1 parent d8520d7 commit 9f791f1

File tree

2 files changed

+54
-6
lines changed

2 files changed

+54
-6
lines changed

resource/template/theme-default/network.html

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,13 @@
8686
],
8787
xAxis: {
8888
type: 'time',
89-
boundaryGap: false
89+
boundaryGap: false,
90+
axisLabel: {
91+
formatter: function (value) {
92+
// 确保时间戳正确格式化
93+
return echarts.format.formatTime('MM-dd hh:mm', value);
94+
}
95+
}
9096
},
9197
yAxis: {
9298
type: 'value',
@@ -178,25 +184,52 @@
178184
});
179185
},
180186
parseMonitorInfo(monitorInfo) {
187+
console.log('Monitor Info:', monitorInfo); // 调试日志
181188
let tSeries = [];
182189
let tLegendData = [];
183190
var lcolors = ['#5470c6', '#91cc75', '#fac858', '#ee6666', '#73c0de', '#3ba272', '#fc8452', '#9a60b4', '#ea7ccc'];
191+
192+
// 检查数据有效性
193+
if (!monitorInfo || !monitorInfo.result || monitorInfo.result.length === 0) {
194+
console.warn('No monitor data available');
195+
this.option.title.text = "No Data Available";
196+
this.myChart.clear();
197+
this.myChart.setOption(this.option);
198+
return;
199+
}
200+
184201
for (let i = 0; i < monitorInfo.result.length; i++) {
185202
var lcolor = lcolors[i % lcolors.length];
186203
var rgbaColorMarker = 'rgba(' + parseInt(lcolor.slice(1, 3), 16) + ',' + parseInt(lcolor.slice(3, 5), 16) + ',' + parseInt(lcolor.slice(5, 7), 16) + ',0.5)';
187204
var rgbaColorBar = 'rgba(' + parseInt(lcolor.slice(1, 3), 16) + ',' + parseInt(lcolor.slice(3, 5), 16) + ',' + parseInt(lcolor.slice(5, 7), 16) + ',0.35)';
188205
let loss = 0;
189206
let data = [];
190207
let datal = [];
208+
209+
// 调试时间戳数据
210+
if (i === 0 && monitorInfo.result[i].created_at && monitorInfo.result[i].created_at.length > 0) {
211+
console.log('First timestamp:', monitorInfo.result[i].created_at[0]);
212+
console.log('Timestamp type:', typeof monitorInfo.result[i].created_at[0]);
213+
console.log('Date from timestamp:', new Date(monitorInfo.result[i].created_at[0]));
214+
}
215+
191216
for (let j = 0; j < monitorInfo.result[i].created_at.length; j++) {
192217
avgDelay = Math.round(monitorInfo.result[i].avg_delay[j]);
218+
let timestamp = monitorInfo.result[i].created_at[j];
219+
220+
// 确保时间戳是有效的数字
221+
if (typeof timestamp !== 'number' || isNaN(timestamp)) {
222+
console.warn('Invalid timestamp:', timestamp);
223+
continue;
224+
}
225+
193226
if (avgDelay > 0 && avgDelay < MaxTCPPingValue) {
194-
data.push([monitorInfo.result[i].created_at[j], avgDelay]);
227+
data.push([timestamp, avgDelay]);
195228
}
196229
else {
197230
loss += 1;
198231
datal.push({
199-
xAxis: monitorInfo.result[i].created_at[j],
232+
xAxis: timestamp,
200233
label: { show: false },
201234
emphasis: { disabled: true },
202235
lineStyle: {
@@ -231,7 +264,14 @@
231264
}
232265
});
233266
}
234-
this.option.title.text = monitorInfo.result[0].server_name;
267+
268+
// 设置标题,优先使用第一个有效的服务器名称
269+
let titleText = "Network Monitor";
270+
if (monitorInfo.result.length > 0 && monitorInfo.result[0].server_name) {
271+
titleText = monitorInfo.result[0].server_name;
272+
}
273+
274+
this.option.title.text = titleText;
235275
this.option.series = tSeries;
236276
this.option.legend.data = tLegendData;
237277
const maxLegendsPerRowMobile = localStorage.getItem("maxLegendsPerRowMobile") ? localStorage.getItem("maxLegendsPerRowMobile") : 2;

service/singleton/api.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,13 @@ func (m *MonitorAPIService) GetMonitorHistories(query map[string]any) *MonitorIn
407407
if server, exists := ServerList[history.ServerID]; exists && server != nil {
408408
serverName = server.Name
409409
} else {
410-
serverName = "Unknown Server"
410+
// 如果内存中没有,尝试从数据库查询
411+
var dbServer model.Server
412+
if err := DB.Where("id = ?", history.ServerID).First(&dbServer).Error; err == nil {
413+
serverName = dbServer.Name
414+
} else {
415+
serverName = "Unknown Server"
416+
}
411417
}
412418
ServerLock.RUnlock()
413419

@@ -420,7 +426,9 @@ func (m *MonitorAPIService) GetMonitorHistories(query map[string]any) *MonitorIn
420426
resultMap[history.MonitorID] = infos
421427
sortedMonitorIDs = append(sortedMonitorIDs, history.MonitorID)
422428
}
423-
infos.CreatedAt = append(infos.CreatedAt, history.CreatedAt.Truncate(time.Minute).Unix()*1000)
429+
// 修复时间戳计算:确保返回正确的毫秒时间戳
430+
timestampMs := history.CreatedAt.Truncate(time.Minute).Unix() * 1000
431+
infos.CreatedAt = append(infos.CreatedAt, timestampMs)
424432
infos.AvgDelay = append(infos.AvgDelay, history.AvgDelay)
425433
}
426434
for _, monitorID := range sortedMonitorIDs {

0 commit comments

Comments
 (0)