1 Star 1 Fork 3

meisongzhu / oshi

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
FAQ.md 7.67 KB
一键复制 编辑 原始数据 按行查看 历史
Daniel Widdis 提交于 2020-08-16 08:20 . 5.2.4 Release

What is the intended use of the API?

Users should create a new instance of SystemInfo and use the getters from this class to access the platform-specific hardware and software interfaces using the respective get*() methods. The interfaces in oshi.hardware and oshi.software.os provide cross-platform functionality. See the main() method of SystemInfoTest for sample code.

Methods return a "snapshot" of current levels. To display values which change over time, it is intended that users poll for information no more frequently than approximately every second. Disk and file system calls may incur some latency and should be polled less frequently. CPU usage calculation precision depends on the relation of the polling interval to both system clock tick granularity and the number of logical processors.

Is the API backwards compatible between versions?

The interfaces and classes in oshi.hardware and oshi.software.os are considered the OSHI API and are guaranteed to be compatible with the same major version. Differences between major versions can be found in the UPGRADING.md document.

Most, if not all, of the platform-specific implementations of these APIs in lower level packages will remain the same, although it is not intended that users access platform-specific code, and some changes may occur between minor versions, most often in the number of arguments passed to constructors or platform-specific methods. Supporting code in the oshi.driver and oshi.util packages may, rarely, change between minor versions, usually associated with organizing package structure or changing parsing methods for efficiency/consistency/ease of use.

Code in the platform-specific oshi.jna.* packages is intended to be temporary and will be removed when that respective code is included in the JNA project.

Is OSHI Thread Safe?

OSHI 5.X is thread safe with the exceptions noted below. @Immutable, @ThreadSafe, and @NotThreadSafe document each class. The following classes are not thread-safe:

  • GlobalConfig does not protect against multiple threads manipulating the configuration programmatically. However, these methods are intended to be used by a single thread at startup in lieu of reading a configuration file. OSHI gives no guarantees on re-reading changed configurations.
  • On non-Windows platforms, the getSessions() method on the OperatingSystem interface uses native code which is not thread safe. While OSHI's methods employ synchronization to coordinate access from its own threads, users are cautioned that other operating system code may access the same underlying data structures and produce unexpected results, particularly on servers with frequent new logins. The oshi.os.unix.whoCommand property may be set to parse the Posix-standard who command in preference to the native implementation, which may use reentrant code on some platforms.
  • The PerfCounterQueryHandler class is not thread-safe but is only internally used in single-thread contexts, and is not intended for user use.

Earlier versions do not guarantee thread safety, but as of version 4.6.0, intended use is thread safe. Classes with setters on them are obviously not thread-safe unless the use of the setters is synchronized across threads. In the case of the HWDiskStore, this synchronization must extend to the HWPartition objects associated with that disk store.

Prior to version 4.1.0, there is no guarantee of thread safety and it should not be assumed.

What minimum Java version is required?

OSHI 3.x is compatible with Java 7, but will not see any added features.

OSHI 4.x and later require minimum Java 8 compatibility. This minimum level will be retained through at least 2026.

In the future, OSHI may include a new artifact targeting JDK 17 and leveraging JPMS, while maintaining feature parity with the JDK 8 version.

Which operating systems are supported?

OSHI has been implemented and tested on the following systems. Some features may work on earlier versions.

  • Windows 7 and higher. (Nearly all features work on Vista and most work on Windows XP.)
  • macOS version 10.6 (Snow Leopard) and higher.
  • Linux (Most major distributions) Kernel 2.6 and higher
  • AIX 7.1 (POWER4)
  • FreeBSD 10
  • Solaris 11 (SunOS 5.11)

How do I resolve JNA NoClassDefFound errors?

OSHI uses the latest version of JNA, which may conflict with other dependencies your project (or its parent) includes. If you experience issues with NoClassDefFound errors for JNA artifacts, 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) as a dependency
  • If you are using a parent (e.g., Spring Boot) that includes JNA as a dependency, override the jna.version property

How is OSHI different from SIGAR?

Both OSHI and Hyperic's SIGAR (System Information Gatherer and Reporter) provide cross-platform operating system and hardware information, and are both used to support distributed system monitoring and reporting, among other use cases. The OSHI project was started, and development continues, to overcome specific shortcomings in SIGAR for some use cases. OSHI does have feature parity with nearly all SIGAR functions. Key differences include:

  • Additional DLL SIGAR's implementation is primarily in native C, compiled separately for its supported operating systems. It therefore requires users to download an additional DLL specific to their operating system. This does have a few advantages for specific, targeted use cases, including faster native code routines, and availability of some native compiler intrinsics. In contrast, OSHI accesses native APIs using JNA, which does not require user installation of any additional platform-specific DLLs.
  • Corporate Development / Abandonment SIGAR was developed commercially at Hyperic to support monitoring of their HQ product. Hyperic's products were later acquired by VMWare, which has transitioned away from Hyperic products and have completely abandoned SIGAR. The last release was in 2010 and the last source commit was in 2015. Multiple independent forks by existing users attempt to fix specific bugs/incompatibilities but none has emerged as a maintained/released fork. In contrast, OSHI's development has been entirely done by open source volunteers, and it is under active development as of 2020.
  • Support SIGAR is completely unsupported by its authors, and there is no organized community support. OSHI is supported actively to fix bugs, respond to questions, and implement new features.

Does OSHI work on Raspberry Pi hardware?

Yes, most of the Linux code works here and other Pi-specific code has been implemented but has seen limited testing. As the developers do not have a Pi to test on, users reporting issues should be prepared to help test solutions.

Will you implement ... ?

Maybe! If you can contribute all the code to implement the feature, it will almost certainly be added. Even if you can't code but can provide pointers to where the information can be found cross-platform, your feature has a good chance. Otherwise, you can always submit an issue to ask, but are at the mercy of the developers' time, enthusiasm level, and the availability of documentation for the feature.

马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/meisongzhu/oshi.git
git@gitee.com:meisongzhu/oshi.git
meisongzhu
oshi
oshi
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891