Package com.iizix.os

Class OSSystemInfo<INFO>


  • public class OSSystemInfo<INFO>
    extends java.lang.Object
    Package to retrieve system information from the OS.
    Author:
    Christopher Mindus
    • Field Detail

      • DEFAULT_INTERVAL

        public static final long DEFAULT_INTERVAL
        The default history gatherer interval: 30 seconds.
        See Also:
        Constant Field Values
    • Constructor Detail

      • OSSystemInfo

        public OSSystemInfo​(IAdditonalInformation<INFO> informationProvider)
        The constructor.
        Parameters:
        informationProvider - The additional information provider to be stored with the history data, or null for none.
    • Method Detail

      • getBasic

        public static OSSystemInfo.Basic getBasic()
        Gets the basic information.

        If a security manager prohibits access to the OS information, a warning message is logged in the console.

        Returns:
        The basic information, or null if the OS management bean failed loading or a security manager restricts access to the OS information.
      • getSystemLoadAverage

        public static double getSystemLoadAverage()
        Gets the average load during the last minute.
        Returns:
        The load between 0.0 to 1.0, negative if not available.
      • getAvailableProcessors

        public static int getAvailableProcessors()
        Gets the number of processors available to the Java virtual machine. Note that this value may change during the JVM lifetime.
        Returns:
        The number of processors, never smaller than 1.
      • getDetails

        public static OSSystemInfo.Details getDetails()
        Gets detailed information of the OS and process memory/swap space usage and CPU load.
        Returns:
        The details instance or null if not supported.
      • startHistory

        public boolean startHistory​(long interval)
        Starts the history gatherer. This clears the history. If the gathering information is not available, a warning message is logged, otherwise an information message is logged about the start.
        Parameters:
        interval - In milliseconds.
        Returns:
        true for OK, false if already started or history not available due to security restrictions.
      • setMaxHistorySize

        public void setMaxHistorySize​(int maxSize)
        Sets the maximum number of entries in the history.
        Parameters:
        maxSize - The maximum size, between 100 and 100_000.
        Throws:
        java.lang.IllegalArgumentException - If range is invalid.
      • getHistoryInterval

        public long getHistoryInterval()
        Gets the interval used for gathering of history entries.
        Returns:
        Interval in milliseconds, zero if never started.
      • isGatheringHistory

        public boolean isGatheringHistory()
        Checks if history is being gathered.
        Returns:
        true if timer is running, false otherwise.
      • stopHistory

        public boolean stopHistory()
        Stops the history gatherer.
        Returns:
        true for OK, false if already stopped or never started.
      • getHistory

        public OSSystemInfo.HistoryEntry<INFO>[] getHistory​(long start)
        Gets the history entries gathered between a date up to the last available entry. The history entries are gathered at specific interval defined at start of history.
        Parameters:
        start - The start time for the events in milliseconds since the Epoch, or zero for all history entries.
        Returns:
        The entries, possibly empty array.