使用第三方jar包
com.github.oshi
oshi-core
3.5.0
java代码
import oshi.SystemInfo;
import oshi.hardware.CentralProcessor;
import oshi.hardware.HWDiskStore;
import oshi.hardware.HardwareAbstractionLayer;
import oshi.util.FormatUtil;
import java.util.Properties;
public class HardWareUtil {
public R getServerHardWareInfo(){
R r = new R();
ServerHardware serverHardware = new ServerHardware();
SystemInfo si = new SystemInfo();
HardwareAbstractionLayer hal = si.getHardware();
Properties props=System.getProperties();
serverHardware.setOsName(props.getProperty("os.name"));
serverHardware.setOsVersion(props.getProperty("os.version"));
serverHardware.setOsArch(props.getProperty("os.arch"));
CentralProcessor processor =hal.