Library "OSHI" to get system information in Java


This is a memo about a library called OSHI that can get system information in Java.

Difference from Sigar

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.



dependencies {
    compile group: 'com.github.oshi', name: 'oshi-core', version: '3.13.0'

Try using

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.

OS information

var si = new SystemInfo();
var os = si.getOperatingSystem();
//OS type
System.out.println(os.getFamily());  // macOS
System.out.println(os.getVersion().getVersion());  // 10.14.2
System.out.println(os.getManufacturer());  // Apple
//How many bits
System.out.println(os.getBitness());  // 64
//Code name
System.out.println(os.getVersion().getCodeName());  // Mojave

CPU information

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
System.out.println(cpu.getName());  // Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
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

Memory information

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

USB device

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")) {
        System.out.println(usb.getName());  // USB Laser Mouse
        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.

Reference link

Recommended Posts

Library "OSHI" to get system information in Java
Get EXIF information in Java
How to get the date in java
How to get Class from Element in Java
How to get information about associated tables in many-to-many tables
Source used to get the redirect source URL in Java
[Java] Get KClass in Java [Kotlin]
How to get the class name / method name running in Java
Easily get an integer from a system property in Java
How to use Java HttpClient (Get)
Multithreaded to fit in [Java] template
How to get parameters in Spark
Log output to file in Java
Welcome to the Java Library Swamp! !!
How to use classes in Java?
How to name variables in Java
Try to implement Yubaba in Java
Get stuck in a Java primer
How to concatenate strings in java
[Java] Get date information 10 days later using milliseconds in the Date class
Examine the system information of AWS Lambda operating environment in Java
How to get the length of an audio file in java
How to implement date calculation in Java
How to implement Kalman filter in Java
Multilingual Locale in Java How to use Locale
How to get date data in Ruby
Sample code to get key JDBC type values in Java + H2 Database
Java reference to understand in the figure
Try to implement n-ary addition in Java
Get caller information from stack trace (java)
Java Artery-Easy to use unit test library
How to do base conversion in Java
[Java] Use cryptography in the standard library
Change List <Optional <T >> to Optional <List <T >> in Java
How to fix system date in JUnit
[Java] How to get the current directory
[Java] Get tag information from music files
Convert SVG files to PNG files in Java
How to implement coding conventions in Java
How to embed Janus Graph in Java
[Rails] How to get the user information currently logged in with devise
[Rails] Use devise to get information about the currently logged in user
Inexperienced learning methods to get Java Silver 11
How to get the value after "_" in Windows batch like Java -version
I want to get the IP address when connecting to Wi-Fi in Java
Get history from Zabbix server in Java
How to get the absolute path of a directory running in Java
Add footnotes to Word documents in Java
[Java Bronze] 5 problems to keep in mind
How to publish a library in jCenter
Sample to unzip gz file in Java
Java to C and C to Java in Android Studio
Add SameSite attribute to cookie in Java
How to create your own annotation in Java and get the value
How to get Excel sheet name list in Java (POI vs SAX)
Try adding text to an image in Scala using the Java standard library
Sample code to get the values of major SQL types in Java + MySQL 8.0
Get contextual information such as HttpServletRequest in Jersey
How to get keycloak credentials in interceptor class
Two ways to start a thread in Java + @
Create a CSR with extended information in Java