This is a memo about a library called OSHI that can get system information in Java.
There is another library to get system information, but OSHI is better in the following points.
--Sigar requires native binaries such as DLLs, but OSHI does not. --Sigar cannot be used on Java 9 or later (JVM crashes!) For Windows version, but OSHI can be used without problems.
build.gradle
dependencies {
compile group: 'com.github.oshi', name: 'oshi-core', version: '3.13.0'
}
I will introduce an appropriate excerpt of the information that can be obtained with OSHI. The comment on the right is the output result in my environment.
var si = new SystemInfo();
var os = si.getOperatingSystem();
//OS type
System.out.println(os.getFamily()); // macOS
//version
System.out.println(os.getVersion().getVersion()); // 10.14.2
//Maker
System.out.println(os.getManufacturer()); // Apple
//How many bits
System.out.println(os.getBitness()); // 64
//Code name
System.out.println(os.getVersion().getCodeName()); // Mojave
var si = new SystemInfo();
var hard = si.getHardware();
var cpu = hard.getProcessor();
//Number of physical processes
System.out.println(cpu.getPhysicalProcessorCount()); // 4
//Number of logical processes
System.out.println(cpu.getLogicalProcessorCount()); // 8
//name
System.out.println(cpu.getName()); // Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
//identifier
System.out.println(cpu.getIdentifier()); // Intel64 Family 6 Model 70 Stepping 1
//Vendor ID
System.out.println(cpu.getVendor()); // GenuineIntel
//Number of context switches
System.out.println(cpu.getContextSwitches()); // 130336
//Road average
System.out.println(cpu.getSystemLoadAverage()); // 2.65576171875
var si = new SystemInfo();
var hard = si.getHardware();
var memory = hard.getMemory();
//Total memory capacity
System.out.println(memory.getTotal()); // 17179869184
//Total swap capacity
System.out.println(memory.getSwapTotal()); // 1073741824
//Page size
System.out.println(memory.getPageSize()); // 4096
//Usable capacity
System.out.println(memory.getAvailable()); // 5858844672
var si = new SystemInfo();
var hard = si.getHardware();
var usbs = hard.getUsbDevices(false);
for(var usb : usbs) {
//There are various things, so I will focus on the mouse for the time being
if(usb.getName().contains("Mouse")) {
//name
System.out.println(usb.getName()); // USB Laser Mouse
//Maker
System.out.println(usb.getVendor()); // Logitech
}
}
var si = new SystemInfo();
var hard = si.getHardware();
var sensor = hard.getSensors();
//CPU temperature
System.out.println(sensor.getCpuTemperature()); // 48.75
//CPU voltage
System.out.println(sensor.getCpuVoltage()); // 3.63
//CPU fan speed
System.out.println(Arrays.toString(sensor.getFanSpeeds())); // [2159, 2000]
I can't introduce all of them because there are so many, but you can get various information such as file system information, disk information, process information, sound card information, power supply information, etc.
Recommended Posts