| | |
| | | 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; |
| | |
| | | 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); |