Class SystemInfo

java.lang.Object
oshi.SystemInfo

public class SystemInfo extends Object
System information. This is the main entry point to OSHI, using JNA for native access.

This object provides getters which instantiate the appropriate platform-specific implementations of OperatingSystem (software) and HardwareAbstractionLayer (hardware).

Quick start:

SystemInfo si = new SystemInfo();
HardwareAbstractionLayer hal = si.getHardware();
OperatingSystem os = si.getOperatingSystem();

// CPU usage (blocks for 1 second)
double cpuLoad = hal.getProcessor().getSystemCpuLoad(1000L);

// Memory
GlobalMemory mem = hal.getMemory();
long availableBytes = mem.getAvailable();
Platform-specific Hardware and Software objects are retrieved via memoized suppliers and cached on the SystemInfo instance. To conserve memory at the cost of additional processing time, create a new SystemInfo for subsequent calls. To conserve processing time at the cost of additional memory usage, re-use the same instance.

This implementation uses JNA for native access and supports all OSHI platforms (Windows, macOS, Linux, Android, FreeBSD, OpenBSD, Solaris, AIX). Android is routed through the Linux implementations. For JDK 25+, the oshi-core-java25 module provides an alternative entry point (oshi.ffm.SystemInfo) that uses the Foreign Function and Memory (FFM) API for potentially better performance on supported platforms (currently Windows, macOS, and Linux).

Both this class and the FFM entry point require native access. Starting with JEP 472 (JDK 24), the JVM warns when native code is loaded, and a future JDK release will require --enable-native-access. Applications that cannot enable native access can depend on the oshi-common module alone and implement the OSHI interfaces without native calls. See the oshi package documentation for details.

  • Constructor Details

    • SystemInfo

      public SystemInfo()
      Create a new instance of SystemInfo. This is the main entry point to OSHI and provides access to cross-platform code.

      Platform-specific Hardware and Software objects are retrieved via memoized suppliers. To conserve memory at the cost of additional processing time, create a new version of SystemInfo() for subsequent calls. To conserve processing time at the cost of additional memory usage, re-use the same SystemInfo object for future queries.

  • Method Details

    • getCurrentPlatform

      @Deprecated public static PlatformEnum getCurrentPlatform()
      Deprecated.
      Gets the PlatformEnum value representing this system.
      Returns:
      Returns the current platform
    • getOperatingSystem

      public oshi.software.os.OperatingSystem getOperatingSystem()
      Creates a new instance of the appropriate platform-specific OperatingSystem.
      Returns:
      A new instance of OperatingSystem.
    • getHardware

      public oshi.hardware.HardwareAbstractionLayer getHardware()
      Creates a new instance of the appropriate platform-specific HardwareAbstractionLayer.
      Returns:
      A new instance of HardwareAbstractionLayer.