Package com.iizix.os
Class OSSystemInfo<INFO>
java.lang.Object
com.iizix.os.OSSystemInfo<INFO>
Package to retrieve system information from the OS.
- Author:
- Christopher Mindus
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
Basic OS and JVM information class.static final class
Detailed information class.static class
The history entry information.Field Summary
Modifier and TypeFieldDescriptionstatic final long
The default history gatherer interval: 5 seconds.Constructor Summary
Method Summary
Modifier and TypeMethodDescriptionstatic int
Gets the number of processors available to the Java virtual machine.static OSSystemInfo.Basic
getBasic()
Gets the basic information.static OSSystemInfo.Details
Gets detailed information of the OS and process memory/swap space usage and CPU load.getHistory
(long start) Gets the history entries gathered between a date up to the last available entry.long
Gets the interval used for gathering of history entries.static double
Gets the average load during the last minute.boolean
Checks if history is being gathered.void
setMaxHistorySize
(int maxSize) Sets the maximum number of entries in the history.boolean
startHistory
(long interval) Starts the history gatherer.boolean
Stops the history gatherer.
Field Details
DEFAULT_INTERVAL
public static final long DEFAULT_INTERVALThe default history gatherer interval: 5 seconds.- See Also:
Constructor Details
OSSystemInfo
The constructor.- Parameters:
informationProvider
- The additional information provider to be stored with the history data, or null for none.
Method Details
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.0d
to1.0d
, 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
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:
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
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.