Class OSSystemInfo<INFO>
java.lang.Object
com.iizix.os.OSSystemInfo<INFO>
Package to retrieve system information from the OS.
The history gatherer (startHistory(long)) samples at the live interval (DEFAULT_LIVE_INTERVAL, one second) into a live buffer of the last DEFAULT_LIVE_SIZE samples, and every history interval's sample into the history (getHistory(long)). A listener (addLiveListener(ILiveListener)) is told of every live sample on the gatherer's timer thread, inside the gatherer's monitor: it must be quick and never throw (CC-SERVERADMIN-LIVE-DASHBOARD).
- Author:
- Christopher Mindus
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBasic OS and JVM information class.static final classDetailed information class.static classThe history entry information.static interfaceA listener of the live samples (CC-SERVERADMIN-LIVE-DASHBOARD): told of every entry the history gatherer adds to the live buffer, on the gatherer's timer thread and inside its monitor, so that the entries a listener receives follow the bufferaddLiveListener(ILiveListener)returned without a gap or a repetition.Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longThe default history gatherer interval: 5 seconds.static final longThe default live sampling interval: 1 second (CC-SERVERADMIN-LIVE-DASHBOARD, LM-D-3).static final intThe default size of the live buffer: 5 minutes at the default live interval (5 * 60 = 300 entries).Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionaddLiveListener(OSSystemInfo.ILiveListener<INFO> listener) Adds a listener of the live samples and gets the live buffer in the same breath: every entry the listener is told of afterwards is newer than the last one returned.static intGets the number of processors available to the Java virtual machine.static OSSystemInfo.BasicgetBasic()Gets the basic information.static OSSystemInfo.DetailsGets 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.longGets the interval used for gathering of history entries.Gets the newest entry of the live buffer.Gets the live buffer: the last entries sampled at the live interval, oldest first.longGets the live interval.static doubleGets the average load during the last minute.booleanChecks if a listener of the live samples is present.booleanChecks if history is being gathered.static StringosNameOf(WindowsVersion windows, String javaName) Gets the name of the operating system for a page that shows the name and the version in two places (OSSystemInfo.Basic.osName, ServerAdmin's Dashboard).static StringosVersionOf(WindowsVersion windows, String javaVersion) Gets the version of the operating system for a page that shows the name and the version in two places (OSSystemInfo.Basic.osVersion).booleanremoveLiveListener(OSSystemInfo.ILiveListener<INFO> listener) Removes a listener of the live samples.voidsetLiveInterval(long liveInterval) Sets the live interval, the timer's tick: in effect at the nextstartHistory(long).voidsetMaxHistorySize(int maxSize) Sets the maximum number of entries in the history.voidsetMaxLiveSize(int maxLiveSize) Sets the maximum number of entries in the live buffer (CC-SERVERADMIN-LIVE-DASHBOARD).booleanstartHistory(long interval) Starts the history gatherer.booleanStops the history gatherer.
Field Details
DEFAULT_INTERVAL
public static final long DEFAULT_INTERVALThe default history gatherer interval: 5 seconds.- See Also:
DEFAULT_LIVE_INTERVAL
public static final long DEFAULT_LIVE_INTERVALThe default live sampling interval: 1 second (CC-SERVERADMIN-LIVE-DASHBOARD, LM-D-3).- See Also:
DEFAULT_LIVE_SIZE
public static final int DEFAULT_LIVE_SIZEThe default size of the live buffer: 5 minutes at the default live interval (5 * 60 = 300 entries).- 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.0dto1.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.
setMaxLiveSize
public void setMaxLiveSize(int maxLiveSize) Sets the maximum number of entries in the live buffer (CC-SERVERADMIN-LIVE-DASHBOARD).- Parameters:
maxLiveSize- The maximum size, between 10 and 100_000.- Throws:
IllegalArgumentException- If range is invalid.
setLiveInterval
public void setLiveInterval(long liveInterval) Sets the live interval, the timer's tick: in effect at the nextstartHistory(long).- Parameters:
liveInterval- In milliseconds, at least 10.- Throws:
IllegalArgumentException- If the interval is below 10 ms.
getLiveInterval
public long getLiveInterval()Gets the live interval.- Returns:
- The interval in milliseconds, the timer's tick when the history is gathered.
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.
getLiveHistory
Gets the live buffer: the last entries sampled at the live interval, oldest first.- Returns:
- The entries, possibly empty array.
getLatest
Gets the newest entry of the live buffer.- Returns:
- The entry, or null when the history gatherer was never started.
addLiveListener
Adds a listener of the live samples and gets the live buffer in the same breath: every entry the listener is told of afterwards is newer than the last one returned. Adding the same listener twice has no effect.- Parameters:
listener- The listener.- Returns:
- The live buffer, oldest first.
- Throws:
NullPointerException- If the listener is null.
removeLiveListener
Removes a listener of the live samples.- Parameters:
listener- The listener.- Returns:
- true if the listener was removed, false if it was not added.
hasLiveListeners
public boolean hasLiveListeners()Checks if a listener of the live samples is present.- Returns:
- true for at least one listener, false for none: nothing is told to anyone at a tick.
osNameOf
Gets the name of the operating system for a page that shows the name and the version in two places (OSSystemInfo.Basic.osName, ServerAdmin's Dashboard). On Windows it is the name part of the description of the Windows version (WindowsVersion.getName(), e.g. "Windows 11"): the description that the server's program info, the start line of its log and the header of iiziGo's log files print. On any other operating system it is the Java VM'sos.name, which those print there too.- Parameters:
windows- The Windows version,com.iizix.SystemConfig.windowsVersion: null when not on Windows.javaName- The Java VM'sos.name.- Returns:
- The name.
osVersionOf
Gets the version of the operating system for a page that shows the name and the version in two places (OSSystemInfo.Basic.osVersion). On Windows it is the version part of the description of the Windows version (WindowsVersion.getVersionText(), e.g. "25H2 (build 26200.7171)"), so that the name, a blank and the version are that description: the Java VM'sos.versionsays "10.0" on Windows 10, on Windows 11 and on every Windows Server since 2016 alike. On any other operating system, and on a Windows whose registry could not be read (no version part), it is the Java VM'sos.version.- Parameters:
windows- The Windows version,com.iizix.SystemConfig.windowsVersion: null when not on Windows.javaVersion- The Java VM'sos.version.- Returns:
- The version.