MCPcopy
hub / github.com/oshi/oshi

github.com/oshi/oshi @oshi-parent-java11-6.1.0 sqlite

repository ↗ · DeepWiki ↗ · release oshi-parent-java11-6.1.0 ↗
3,370 symbols 9,788 edges 451 files 1,431 documented · 42%
README

OSHI

MIT License Maven central first-timers-only Tidelift Travis Build Status Appveyor Build status Cirrus Build Status Windows CI macOS CI Linux CI FreeBSD CI OpenBSD CI Solaris CI AIX CI SonarQube Bugs SonarQube Vulnerabilities SonarQube Maintainability SonarQube Reliability SonarQube Security Coverity Scan Build Status Codacy Grade Code Quality: Java CodeQL Coverage Status Scrutinizer Code Quality Openhub Stats github-sponsor buymeacoffee

OSHI is a free JNA-based (native) Operating System and Hardware Information library for Java. It does not require the installation of any additional native libraries and aims to provide a cross-platform implementation to retrieve system information, such as OS version, processes, memory and CPU usage, disks and partitions, devices, sensors, etc.

Supported platforms

Windows • Linux • macOS • Unix (AIX, FreeBSD, OpenBSD, Solaris)

Essentials

Supported features

  • Computer System and firmware, baseboard
  • Operating System and Version/Build
  • Physical (core) and Logical (hyperthreaded) CPUs, processor groups, NUMA nodes
  • System and per-processor load, usage tick counters, interrupts, uptime
  • Process uptime, CPU, memory usage, user/group, command line args, thread details
  • Physical and virtual memory used/available
  • Mounted filesystems (type, usable and total space, options, reads and writes)
  • Disk drives (model, serial, size, reads and writes) and partitions
  • Network interfaces (IPs, bandwidth in/out), network parameters, TCP/UDP statistics
  • Battery state (% capacity, time remaining, power usage stats)
  • USB Devices
  • Connected displays (with EDID info), graphics and audio cards
  • Sensors (temperature, fan speeds, voltage) on some hardware

Downloads

Stable Release Version Current Development Version Dependencies
oshi-core-6.0.0 oshi-core-6.1.0-SNAPSHOT JNASLF4J
Java 11 (JPMS) Version Current Development Version
oshi-core-java11-6.0.0 oshi-core-java11-6.1.0-SNAPSHOT
Java 6 Version Current Development Version
oshi-core-3.14.0 None

Usage

  1. Include OSHI and its dependencies on your classpath. We strongly recommend you add OSHI as a dependency to your project dependency manager such as Maven or Gradle. You can find the appropriate syntax to include OSHI here.

  2. Create a new instance of SystemInfo

  3. Use the getters from SystemInfo to access hardware or operating system components, such as:

SystemInfo si = new SystemInfo();
HardwareAbstractionLayer hal = si.getHardware();
CentralProcessor cpu = hal.getProcessor();

See the PERFORMANCE document for general CPU/Memory tradeoffs and specific Windows (WMI) recommendations depending upon your application.

See the FAQ document for common implementation and calculation questions.

Some settings are configurable in the oshi.properties file, which may also be manipulated using the GlobalConfig class. This should be done at startup, as configuration is not thread-safe and OSHI does not guarantee re-reading the configuration during operation.

The oshi-demo artifact includes several proof-of-concept examples of using OSHI to obtain information, including a basic Swing GUI.

Note: OSHI uses the latest version of JNA. If you experience a NoClassDefFoundError or NoSuchMethodError issues with JNA artifacts, you likely have an older version of either jna or jna-platform in your classpath from a transitive dependency on another project. Consider one or more of the following steps to resolve the conflict: - Listing OSHI earlier (or first) in your dependency list - Specifying the most recent version of JNA (both jna and jna-platform artifacts) in your pom.xml as dependencies. - If you are using the Spring Boot Starter Parent version 2.2 and earlier that includes JNA as a dependency: - Upgrade to version 2.3 which does not have a JNA dependency (preferred) - If you must use version 2.2 or earlier, override the jna.version property to the latest JNA version.

Support

  • For bug reports, feature requests, or general questions about OSHI's longer term plans, please create an issue.
  • For help integrating OSHI into your own project or maintainer code review of your PRs, tag @dbwiddis in issues or pull requests on your project site.
  • For "how to" questions regarding use of the API, consult examples in the oshi-demo project, create an issue, or search on Stack Overflow using the oshi tag, asking a new question if it hasn't been answered before.
  • To say thanks to OSHI's primary maintainer, you can sponsor him or buy him a coffee.

OSHI for enterprise

Available as part of the Tidelift Subscription

The maintainers of OSHI and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.

Security contact information

To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.

Output

OSHI provides output directly via Java methods for each of its interfaces. By periodically polling dynamic information (e.g., every second), users can calculate and track changes.

You can see more examples and run the SystemInfoTest and see the full output for your system by cloning the project and building it with Maven:

git clone https://github.com/oshi/oshi.git && cd oshi

./mvnw test-compile -pl oshi-core exec:java \
  -Dexec.mainClass="oshi.SystemInfoTest" \
  -Dexec.classpathScope="test"

In addition, the oshi-demo project includes an OshiGui class implementing a basic Swing GUI offering suggestions for potential visualizations using OSHI in a UI, monitoring, or alerting application, as shown below. For a more advanced GUI based on this approach, see the MooInfo project.

General information about the operating system and computer system hardware: Operating System and Hardware

By measuring ticks (user, nice, system, idle, iowait, and irq) between time intervals, percent usage can be calculated. Per-processor information is also provided. CPU Usage

Process information including CPU and memory per process is available. Process Statistics

Memory and swapfile information is available. Memory Statistics

Statistics for the system battery are provided:

Power Sources:
 Name: InternalBattery-0, Device Name: bq20z451,
 RemainingCapacityPercent: 100.0%, Time Remaining: 5:42, Time Remaining Instant: 5:42,
 Power Usage Rate: -16045.216mW, Voltage: 12.694V, Amperage: -1264.0mA,
 Power OnLine: false, Charging: false, Discharging: true,
 Capacity Units: MAH, Current Capacity: 7213, Max Capacity: 7315, Design Capacity: 7336,
 Cycle Count: 6, Chemistry: LIon, Manufacture Date: 2019-06-11, Manufacturer: SMP,
 SerialNumber: D869243A2U3J65JAB, Temperature: 30.46°C

The EDID for each Display is provided. This can be parsed with various utilities for detailed information. OSHI provides a summary of selected data.

``` Displays: Display 0: Manuf. ID=SAM, Product ID=2ad, Analog, Serial=HA19, ManufDate=3/2008, EDID v1.3 41 x 27 cm (16.1 x 10.6 in) Preferred Timing: Clock 106MHz, Active Pixels 3840x2880 Range Limits: Field Rate 56-75 Hz vertical, 30-81

Extension points exported contracts — how you extend this code

VirtualMemory (Interface)
The VirtuallMemory class tracks information about the use of a computer's virtual memory (swap file) which temporarily m [8 …
oshi-core/src/main/java/oshi/hardware/VirtualMemory.java
Baseboard (Interface)
The Baseboard represents the system board, also called motherboard, logic board, etc. [6 implementers]
oshi-core/src/main/java/oshi/hardware/Baseboard.java
FileSystem (Interface)
The File System is a logical arrangement, usually in a hierarchial tree, where files are placed for storage and retrieva [8 …
oshi-core/src/main/java/oshi/software/os/FileSystem.java
PdhCounterWildcardProperty (Interface)
Contract for Counter Property Enums [7 implementers]
oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
PdhCounterProperty (Interface)
Contract for Counter Property Enums [5 implementers]
oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQuery.java

Core symbols most depended-on inside this repo

get
called by 600
oshi-core/src/main/java/oshi/util/Memoizer.java
memoize
called by 158
oshi-core/src/main/java/oshi/util/Memoizer.java
runNative
called by 152
oshi-core/src/main/java/oshi/util/ExecutingCommand.java
getValue
called by 134
oshi-core/src/main/java/oshi/hardware/NetworkIF.java
parseLongOrDefault
called by 120
oshi-core/src/main/java/oshi/util/ParseUtil.java
getProcessID
called by 111
oshi-core/src/main/java/oshi/software/os/OSProcess.java
getName
called by 99
oshi-core/src/main/java/oshi/hardware/Firmware.java
getOrDefault
called by 98
oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxPowerSource.java

Shape

Method 2,831
Class 443
Enum 57
Interface 39

Languages

Java100%

Modules by API surface

oshi-core/src/main/java/oshi/util/ParseUtil.java55 symbols
oshi-core/src/test/java/oshi/util/ParseUtilTest.java51 symbols
oshi-core/src/main/java/oshi/hardware/CentralProcessor.java47 symbols
oshi-core/src/main/java/oshi/software/os/linux/LinuxOSProcess.java40 symbols
oshi-core/src/main/java/oshi/software/os/InternetProtocolStats.java39 symbols
oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java38 symbols
oshi-core/src/main/java/oshi/software/os/unix/solaris/SolarisOSProcess.java38 symbols
oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSProcess.java37 symbols
oshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSProcess.java37 symbols
oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java36 symbols
oshi-core/src/main/java/oshi/software/os/OSProcess.java35 symbols
oshi-core/src/main/java/oshi/software/os/unix/aix/AixOSProcess.java34 symbols

Dependencies from manifests, versioned

${project.groupId}:oshi-core
${project.groupId}:oshi-demo
com.puppycrawl.tools:checkstyle
de.skuzzle.enforcer:restrict-imports-enforcer-rule
javax.xml.bind:jaxb-api
net.java.dev.jna:jna-jpms
net.java.dev.jna:jna-platform-jpms
net.trajano.wagon:wagon-git
org.apache.maven.skins:maven-fluido-skin
org.apache.maven.wagon:wagon-ssh
org.hamcrest:hamcrest

For agents

$ claude mcp add oshi \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact