Code Monkey home page Code Monkey logo

oshi6's Introduction

OSHI

MIT License Maven Central first-timers-only Openhub Stats

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
  • macOS
  • Linux (Android)
  • UNIX (AIX, FreeBSD, OpenBSD, Solaris)

Documentation

Downloads and Dependency Management

Stable Release Version

Current Development (SNAPSHOT) downloads

Usage

  1. Include OSHI and its dependencies on your classpath.
    • We strongly recommend you add oshi-core as a dependency to your project dependency manager such as Maven or Gradle.
    • For Android, you'll need to add the AAR artifact for JNA and exclude OSHI's transitive (JAR) dependency.
    • See the FAQ if you encounter NoClassDefFoundError or NoSuchMethodError problems.
  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 SystemInfoTest.java for examples. To see sample output for your machine:

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"

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.

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

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 the 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 Tidelift

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.

Continuous Integration Test Status

Appveyor Build status Cirrus Build Status Windows CI macOS CI Linux CI Unix CI SonarQube Bugs SonarQube Vulnerabilities SonarQube Maintainability SonarQube Reliability SonarQube Security Coverity Scan Build Status Codacy Grade CodeQL Coverage Status

How Can I Help?

OSHI originated as a platform-independent library that did not require additional software and had a license compatible with both open source and commercial products. We have developed a strong core of features on major Operating Systems, but we would love for you to help by:

  • Testing! Our CI testing is limited to a few platforms. Download and test the program on various operating systems/versions and hardware and help identify gaps that our limited development and testing may have missed. Specific high priority testing needs include:
    • Windows systems with over 64 logical processors
    • Raspberry Pi
    • Less common Linux distributions
  • Contributing code. See something that's not working right or could work better? Help us fix it! New contributors are welcome.
  • Documenting implementation. Our Wiki is sparse and the oshi-demo artifact is a place to host proof-of-concept ideas. Want to help new users follow in your footsteps?
  • Suggesting new features. Do you need OSHI to do something it doesn't currently do? Let us know.

Contributing to OSHI

Acknowledgments

Many thanks to the following companies for providing free support of Open Source projects including OSHI:

License

This project is licensed under the MIT License.

oshi6's People

Contributors

cilki avatar dbwiddis avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

oshi6's Issues

Official definitions of common terms

We need to agree on some common definitions to make it easier to discuss design and write documentation. I propose the following initial set:

Term Definition Example
Attribute A specific property of some aspect of the system guid, vendor, name
Component A POJO container for related attributes Cpu, Gpu, ...
Index An interface that defines all attributes of a component CpuIndex, GpuIndexWindows
Driver TBD

Logging vs. Exceptions vs. Result Objects

Early in OSHI's development, the code was littered with UnsupportedOperationExceptions. This seems an appropriate response when we're asking for data that simply doesn't exist (e.g., load average on Windows). But it requires the user to explicitly handle these exceptions.

I moved away from exceptions into log messages, which allowed a more finely grained control of what was a normal problem vs. failure (warnings vs. errors etc.) and just returned sensible defaults (negative values, or 0, or empty strings, or empty collections). This introduces the opposite problem, of not allowing the user to handle exception types.

OSHI needs a standardized method of handling these types of situations:

  • Data is undefined on a platform (Windows load avg.)
  • Data is not easily obtained on a platform (Windows open files)
  • Data requires elevated permissions and/or software installs that the user doesn't have (lots of Linux stuff)
  • Data should normally return but happened to fail in this case (Sensor readings) but the user can try again
  • Data wasn't updated because you asked for it too recently (tick counts < 1 second apart).

We can use Optional results in key places, or encapsulate the result in our own OshiResult class that includes:

  • Result object
  • Result type (similar to how VARIANT is used in JNA)
  • Result timestamp
  • Result error value/enum/etc.

Configurability for OSHI

For this version, now that we'll start decoupling the fetching, the caching, and the API - plus the implementation of a more standard vs specialized set of APIs -, we should start looking into setting a mechanism (or two) for configuring OSHI.

How to handle elevated permissions

Linux serial number, for example, requires user cooperation (elevated permissions for user or a file, or a software package). What do we return?

There are a few places in the code where we have "fallback" sensible defaults. Should we flag that these are different due to a permissions issue?

Jenkins test coverage

From oshi/oshi#427

I am more than happy to test in more places and on more systems. I have very little time to figure out how to set it all up myself! Can you help set it up?

I can do it and I can probably host it at my house. It's just a matter of finding suitable, inexpensive hardware and identifying what the test environments need to be. I think ideally we would want a few bare metal setups in certain cases (specifically for testing battery/power states), a raspberry pi, and VMs for the rest. Maybe we can setup a gofundme or something for getting hardware.

Since we'll know exactly what the hardware (either real or virtual), then we can try unit tests that only run on that specific environment and confirm exact values for the configuration. It would go a long way in terms of confirm accurate measurements and operating system compatibility.

So if i host it, it will not be publicly accessible however it will have its own github account and will add comments to pull requests based on test results (i think).

Finally, as an added bonus, I actually want to setup something for some of my other android projects.

Another thought is if this code base is donated to the apache software foundation, i know they have both a large jenkins cluster and buildbot configurations available with a variety of operating systems. There's a lot of benefits to it and then i wouldn't have to manage a bunch of miscellaneous hardware

Consolidating all the differing parts of OSHI into a better model

I've been thinking on this strongly for a while.
Between issues like #310, and the kind of issues that keep cropping up (specially when asking for new features), I can't help but think that OSHI's model is starting to become a bit of a Frankenstein's monster...

Right now, it's not strange to have somebody ask for a feature only available in a single platform, and OSHI ending up with an extra feature on that platform alone.
In direct opposition, however, the current model will abstract or rename things in some platforms to have them fall in line with another platform.

As far as I can see, we have a few model/design details that need to be addressed:

1. We need a consolidated model across all platforms
2. We need to keep the API as far away from the non-consolidated parts as possible
3. We need a better way of recovering and updating the system info

Side library/module for Event Hooks

I'm opening this issue to follow a converstion that started on #7:
OSHI having the ability to add event handlers to things like changes in values, errors in drivers, etc.

This was brought up by @cilki , and I responded that we should avoid such things in the standard library, to avoid the impact of the extra functionalities to performance, when it's not part of the base requirements of the OSHI library.

My idea for this follows from another idea that we should split the different layers of OSHI5 into separate modules. If so, we can implement multiple OSHI libraries, that connect at different levels with the base modules.

Unit testing and platform testing

Like every library, OSHI needs a solid set of unit tests for the api. With the Driver design pattern, a mock driver can be created that returns configurable values with configurable timings. This should be sufficient for thoroughly testing the api and caching layers.

Testing the drivers (platform testing) will require some additional infrastructure. Travis CI isn't a good fit for this kind of testing because they only have a few images. The platform tests should ideally be run on every architecture of every major OS family and distribution. So that's like 60+ (virtual) machines at least. This is likely to take a long time which is another reason why platform testing should be separate from unit testing.

Docker could reduce the burden for Linux testing, but the sandbox effect may also reduce the benefit of testing on a container. The same could also be said (to a lesser degree I think) for virtual machines.

Most projects wouldn't bother with testing on so many platforms, but I argue that this is important for OSHI considering its purpose.

How to manage driver state?

the way the driver works should not reflect on the way the API works, since the whole point of a Driver Pattern is to abstract such concerns from the API

The only problem is, how can you determine when to release a driver's resources without a cue from a higher layer? Making the lowest layer stateful introduces a session-like architecture to the higher layers.

Originally posted by @cilki in #7 (comment)

Querying remote machines

Hi,
If you are planning to implement handlings which might require an elevated privilege using machines credentials, you can also check whether querying remote machine is viable.
I know this is out of scope for oshi, but adding this feature might be a booster for oshi.
Thanks.

OSHI5 --> OSHI-future

I'm finding a lot more API imporovements/adjustments that I want to make, and foresee an OSHI 5 release long before I expect to see this new project released. I wanted to give a heads up that we might not want to put a specific number on this future redesign/release.

Role of code generation in OSHI 5

About 5 months ago I wrote a small program with JavaPoet that generates the API according to a set of general definitions.

For example, the following YAML file defines a small Nic component:

- Nic:
  - name: The interface's name
      type: String
  - mtu: The interface's maximum transmission unit
      type: Integer
  - ipv4: The interface's IPv4 addresses
      type: String[]
  - luid: The interface's local UID
      type: Long
      platforms: windows
  - guid: The interface's global UID
      type: String
      platforms: windows
  - connected: Whether the interface is connected
      type: Boolean
      platforms: windows
...

The program produced the API component and the interface for the driver (which I call the Index) along with proper JavaDoc on everything. I'm confident that JavaPoet can generate just about any kind of API we come up with, so the question is whether it's a good fit for the project.

Advantages to generating the API

  • Generate hundreds of source files in seconds
  • Places the essence of OSHI into a single definition file
    • Makes it easier to produce a uniform/consistent API
    • Makes it easier and less error-prone to add/change features
  • Changes to the API itself can be propagated quickly and error-free
  • Allows us to relax on DRY if doing so leads to a better API
  • No additional runtime dependencies and integrates well with Maven

Disadvantages to generating the API

  • Flexibility to add special cases to the API is lost
    • Doing so goes against one of our design goals, but could be permissible once or twice
    • This means that the API we come up with must be general enough to suit every feature
  • Another piece of code to write and maintain

I'll update this post with any additional concerns.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.