OshiUtil
Overview
Oshi
is a free Java-based operating system and hardware information library based on JNA. Its Github address is: https://github.com/oshi/oshi.
Its advantage is that it does not require the installation of any other native libraries, and it aims to provide a cross-platform implementation to retrieve system information, such as operating system version, processes, memory and CPU usage, disks and partitions, devices, sensors, etc.
The content that this library can monitor includes:
- Computer system and firmware, motherboard
- Operating system and version/build
- Physical (core) and logical (hyper-threading) CPUs, processor groups, NUMA nodes
- System and load percentage and tick counter for each processor
- CPU uptime, processes and threads
- Process uptime, CPU, memory usage, user/group, command line
- Used/available physical and virtual memory
- Mounted file systems (type, available space and total space)
- Disk drives (model, serial number, size) and partitions
- Network interfaces (IP, bandwidth input/output)
- Battery status (percentage of charge, remaining time, battery usage statistics)
- Connected displays (with EDID information)
- USB devices
- Sensors (temperature, fan speed, voltage)
In other words, with a front-end interface, system monitoring can be completely handled.
Usage
First, introduce the Oshi library:
<dependency>
<groupId>com.github.oshi</groupId>
<artifactId>oshi-core</artifactId>
<version>5.6.1</version>
</dependency>
Then you can call the relevant API to get the relevant information.
For example, if we want to get the total amount of memory:
long total = OshiUtil.getMemory().getTotal();
We can also get some information about the CPU:
CpuInfo cpuInfo = OshiUtil.getCpuInfo();
Console.log(cpuInfo);
CpuInfo{CPU core count = 12, total CPU usage = 12595.0, system CPU usage = 1.74, user CPU usage = 6.69, current CPU wait rate = 0.0, current CPU idle rate = 91.57, CPU utilization rate = 8.43, CPU model information ='AMD Ryzen 5 4600U with Radeon Graphics
1 physical CPU package(s)
6 physical CPU core(s)
12 logical CPU(s)
Identifier: AuthenticAMD Family 23 Model 96 Stepping 1
ProcessorID: xxxxxxxxx
Microarchitecture: unknown'}