1.20升级

This commit is contained in:
dengqichen 2025-12-11 18:03:47 +08:00
parent 1c3c148221
commit 1eb7a6eb6b
3 changed files with 27 additions and 21 deletions

View File

@ -139,10 +139,10 @@ public class ServerMonitorMetricsDTO {
@Schema(description = "发送字节数") @Schema(description = "发送字节数")
private Long txBytes; private Long txBytes;
@Schema(description = "接收速率(MB/s)") @Schema(description = "接收速率(KB/s)")
private BigDecimal rxMBps; private BigDecimal rxMBps;
@Schema(description = "发送速率(MB/s)") @Schema(description = "发送速率(KB/s)")
private BigDecimal txMBps; private BigDecimal txMBps;
} }
@ -253,16 +253,16 @@ public class ServerMonitorMetricsDTO {
@Schema(description = "总发送字节数") @Schema(description = "总发送字节数")
private Long totalTxBytes; private Long totalTxBytes;
@Schema(description = "平均接收速率(MB/s)") @Schema(description = "平均接收速率(KB/s)")
private BigDecimal avgRxMBps; private BigDecimal avgRxMBps;
@Schema(description = "平均发送速率(MB/s)") @Schema(description = "平均发送速率(KB/s)")
private BigDecimal avgTxMBps; private BigDecimal avgTxMBps;
@Schema(description = "峰值接收速率(MB/s)") @Schema(description = "峰值接收速率(KB/s)")
private BigDecimal peakRxMBps; private BigDecimal peakRxMBps;
@Schema(description = "峰值发送速率(MB/s)") @Schema(description = "峰值发送速率(KB/s)")
private BigDecimal peakTxMBps; private BigDecimal peakTxMBps;
} }
} }

View File

@ -229,14 +229,17 @@ public class ServerMonitorServiceImpl implements IServerMonitorService {
.reduce(BigDecimal.ZERO, BigDecimal::add) .reduce(BigDecimal.ZERO, BigDecimal::add)
.divide(BigDecimal.valueOf(successRecords.size()), 2, RoundingMode.HALF_UP); .divide(BigDecimal.valueOf(successRecords.size()), 2, RoundingMode.HALF_UP);
// 网络流量是累计值取最后一个有效值而非求和
ServerMonitor lastRecord = successRecords.get(successRecords.size() - 1);
return ServerMonitor.builder() return ServerMonitor.builder()
.serverId(group.get(0).getServerId()) .serverId(group.get(0).getServerId())
.cpuUsage(avgCpu) .cpuUsage(avgCpu)
.memoryUsage(avgMemory) .memoryUsage(avgMemory)
.memoryUsed(successRecords.get(0).getMemoryUsed()) .memoryUsed(successRecords.get(0).getMemoryUsed())
.diskUsage(successRecords.get(successRecords.size() - 1).getDiskUsage()) .diskUsage(lastRecord.getDiskUsage())
.networkRx(successRecords.stream().mapToLong(m -> m.getNetworkRx() != null ? m.getNetworkRx() : 0).sum()) .networkRx(lastRecord.getNetworkRx())
.networkTx(successRecords.stream().mapToLong(m -> m.getNetworkTx() != null ? m.getNetworkTx() : 0).sum()) .networkTx(lastRecord.getNetworkTx())
.collectTime(group.get(0).getCollectTime()) .collectTime(group.get(0).getCollectTime())
.status(StatusEnum.SUCCESS) .status(StatusEnum.SUCCESS)
.build(); .build();
@ -348,8 +351,9 @@ public class ServerMonitorServiceImpl implements IServerMonitorService {
if (timeDiff > 0 && previous.getNetworkRx() != null && previous.getNetworkTx() != null) { if (timeDiff > 0 && previous.getNetworkRx() != null && previous.getNetworkTx() != null) {
long rxDiff = current.getNetworkRx() - previous.getNetworkRx(); long rxDiff = current.getNetworkRx() - previous.getNetworkRx();
long txDiff = current.getNetworkTx() - previous.getNetworkTx(); long txDiff = current.getNetworkTx() - previous.getNetworkTx();
rxMBps = BigDecimal.valueOf(rxDiff).divide(BigDecimal.valueOf(timeDiff * 1024 * 1024), 2, RoundingMode.HALF_UP); // 改为KB/s单位提高精度原来MB/s对于小流量会四舍五入为0
txMBps = BigDecimal.valueOf(txDiff).divide(BigDecimal.valueOf(timeDiff * 1024 * 1024), 2, RoundingMode.HALF_UP); rxMBps = BigDecimal.valueOf(rxDiff).divide(BigDecimal.valueOf(timeDiff * 1024), 2, RoundingMode.HALF_UP);
txMBps = BigDecimal.valueOf(txDiff).divide(BigDecimal.valueOf(timeDiff * 1024), 2, RoundingMode.HALF_UP);
} }
} }
@ -475,7 +479,7 @@ public class ServerMonitorServiceImpl implements IServerMonitorService {
return null; return null;
} }
// 计算总流量从原始数据 // 计算总流量累计值取最后一个有效值
List<ServerMonitor> successData = data.stream() List<ServerMonitor> successData = data.stream()
.filter(m -> StatusEnum.SUCCESS.equals(m.getStatus()) .filter(m -> StatusEnum.SUCCESS.equals(m.getStatus())
&& m.getNetworkRx() != null && m.getNetworkTx() != null) && m.getNetworkRx() != null && m.getNetworkTx() != null)
@ -485,8 +489,10 @@ public class ServerMonitorServiceImpl implements IServerMonitorService {
return null; return null;
} }
long totalRx = successData.stream().mapToLong(ServerMonitor::getNetworkRx).sum(); // 网络流量是累计值取最后一个值而非求和
long totalTx = successData.stream().mapToLong(ServerMonitor::getNetworkTx).sum(); ServerMonitor lastRecord = successData.get(successData.size() - 1);
long totalRx = lastRecord.getNetworkRx();
long totalTx = lastRecord.getNetworkTx();
// 计算速率统计从已构建的 NetworkMetric 数据中提取 // 计算速率统计从已构建的 NetworkMetric 数据中提取
BigDecimal avgRxMBps = null; BigDecimal avgRxMBps = null;

View File

@ -513,46 +513,46 @@ export const ServerMonitorDialog: React.FC<ServerMonitorDialogProps> = ({
<TabsTrigger value="disk"></TabsTrigger> <TabsTrigger value="disk"></TabsTrigger>
</TabsList> </TabsList>
<TabsContent value="cpu" className="space-y-4"> <TabsContent value="cpu" className="space-y-4 min-h-[400px]">
{monitorData.metrics.cpu && monitorData.metrics.cpu.length > 0 ? ( {monitorData.metrics.cpu && monitorData.metrics.cpu.length > 0 ? (
<ReactECharts <ReactECharts
option={getCpuChartOption()} option={getCpuChartOption()}
style={{ height: '400px', width: '100%' }} style={{ height: '400px', width: '100%' }}
/> />
) : ( ) : (
<div className="flex items-center justify-center h-64 text-muted-foreground"> <div className="flex items-center justify-center h-[400px] text-muted-foreground">
CPU数据 CPU数据
</div> </div>
)} )}
</TabsContent> </TabsContent>
<TabsContent value="memory" className="space-y-4"> <TabsContent value="memory" className="space-y-4 min-h-[400px]">
{monitorData.metrics.memory && monitorData.metrics.memory.length > 0 ? ( {monitorData.metrics.memory && monitorData.metrics.memory.length > 0 ? (
<ReactECharts <ReactECharts
option={getMemoryChartOption()} option={getMemoryChartOption()}
style={{ height: '400px', width: '100%' }} style={{ height: '400px', width: '100%' }}
/> />
) : ( ) : (
<div className="flex items-center justify-center h-64 text-muted-foreground"> <div className="flex items-center justify-center h-[400px] text-muted-foreground">
</div> </div>
)} )}
</TabsContent> </TabsContent>
<TabsContent value="network" className="space-y-4"> <TabsContent value="network" className="space-y-4 min-h-[400px]">
{monitorData.metrics.network && monitorData.metrics.network.length > 0 ? ( {monitorData.metrics.network && monitorData.metrics.network.length > 0 ? (
<ReactECharts <ReactECharts
option={getNetworkChartOption()} option={getNetworkChartOption()}
style={{ height: '400px', width: '100%' }} style={{ height: '400px', width: '100%' }}
/> />
) : ( ) : (
<div className="flex items-center justify-center h-64 text-muted-foreground"> <div className="flex items-center justify-center h-[400px] text-muted-foreground">
</div> </div>
)} )}
</TabsContent> </TabsContent>
<TabsContent value="disk" className="space-y-4"> <TabsContent value="disk" className="space-y-4 min-h-[400px]">
{renderDiskInfo()} {renderDiskInfo()}
</TabsContent> </TabsContent>
</Tabs> </Tabs>