whyclxw
2025-05-28 e16302f9d475c7cc4dd18c5abf1a23cb5502e362
src/main/java/com/whyc/service/ServerStateService.java
@@ -1,10 +1,15 @@
package com.whyc.service;
import cn.hutool.system.oshi.CpuInfo;
import cn.hutool.system.oshi.OshiUtil;
import com.sun.management.OperatingSystemMXBean;
import com.whyc.dto.ShowDTO;
import com.whyc.mapper.ServerStateMapper;
import com.whyc.pojo.ServerState;
import org.springframework.stereotype.Service;
import oshi.hardware.CentralProcessor;
import oshi.hardware.HardwareAbstractionLayer;
import oshi.util.Util;
import javax.annotation.Resource;
import java.io.File;
@@ -71,8 +76,12 @@
        int connRate = (int) (connDivide*100);
        //cpu使用率
        double cpuLoad = osmb.getSystemCpuLoad();
        int cpuLoadRate = (int)(BigDecimal.valueOf(cpuLoad).setScale(2,RoundingMode.CEILING).doubleValue()*100);
        //double cpuLoad = osmb.getSystemCpuLoad();
        CpuInfo cpuInfo = OshiUtil.getCpuInfo();
        double free = cpuInfo.getFree();
        double cpuLoad = 100-free;
        long cpuLoadRate = Math.round(cpuLoad);
        //int cpuLoadRate = (int)(BigDecimal.valueOf(cpuLoad).setScale(2,RoundingMode.CEILING).doubleValue()*100);
        state.setFreeMen(freeMemorySize);
        state.setTotalMem(totalMemorySize);