Class GlobalConfig
src/main/resources/oshi.properties for default values.
Configuration is resolved in the following precedence order (highest wins):
set(String, Object)— programmatic, at runtime- Java system properties (
-Doshi.*) - Environment variables (
OSHI_*) — mapped by uppercasing and replacing dots with underscores - External properties file (
-Doshi.properties.file=/path/to/file) oshi.propertieson the classpath (defaults)
This class is not thread safe if methods manipulating the configuration are used. These methods are intended for use by a single thread at startup, before instantiation of any other OSHI classes. OSHI does not guarantee re-reading of any configuration changes.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classIndicates that a configuration value is invalid. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringA comma-separated list of filesystem types that are network-based and should be excluded from local-only file store listings.static final StringWhether to use systemd on Linux for loading session information when utmp is unavailable or deprecated.static final StringWhether to use udev on Linux for loading hardware information such as USB devices, power sources, and disk information.static final StringA comma-separated list of commands eligible for privilege escalation on Linux.static final StringA comma-separated list of file paths eligible for privileged read viasudo catfallback on Linux when normal file read fails due to permissions.static final StringThe command prefix to prepend for privileged command execution on Linux (e.g.,"sudo -n"for non-interactive sudo).static final StringWhether to log warnings when failing to read process information from the/procpseudo-filesystem on Linux.static final StringWhether to log warnings when failing to read process information via sysctl on macOS.static final StringWhether to allow use of the kstat2 API on Solaris 11.4+.static final StringWhether to use the Posix-standardwhocommand for session information instead of native code.static final StringWhether to perform WMI queries for command lines in a batch for all running processes.static final StringWhether to use "Processor Utility" for System and per-processor CPU Load ticks (on Windows 8 and higher) to match CPU usage with the Windows Task Manager.static final StringThe name of the Windows System event log containing bootup event IDs 12 and 6005, used for a one-time calculation of system boot time that is consistent across process runs regardless of sleep/hibernate cycles.static final StringWhether to attempt to fetch Windows performance counter data for processes and threads fromHKEY_PERFORMANCE_DATAin the registry.static final StringWhether to use the Legacy Processor performance counters for System CPU ticks instead of Processor Information (since Windows 7).static final StringWhether to start a daemon thread to provide load averages on Windows.static final StringWhether to assume any performance counter failure means all counters will fail and revert to WMI backup.static final StringWhether PerfDisk performance counters are disabled.static final StringWhether PerfOS performance counters are disabled.static final StringWhether PerfProc performance counters are disabled.static final StringWhether to update the process state on Windows toSUSPENDEDif all its threads are suspended.static final StringA comma-separated list of filesystem types to treat as pseudo-filesystems and exclude from file store listings.static final StringThe/devfilesystem location.static final StringMemoizer default expiration in milliseconds.static final StringThe/procfilesystem location.static final StringThe/sysfilesystem location.static final StringThe WMI query timeout in milliseconds. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidclear()Clear the configuration.static StringGet the property associated with the given key.static booleanGet thebooleanproperty associated with the given key.static doubleGet thedoubleproperty associated with the given key.static intGet theintproperty associated with the given key.static StringGet theStringproperty associated with the given key.static voidload(Properties properties) Load the givenPropertiesinto the global configuration.static voidReset the given property to its default value.static voidSet the given property, overwriting any existing value.
-
Field Details
-
OSHI_UTIL_MEMOIZER_EXPIRATION
Memoizer default expiration in milliseconds. Cached return values will be refreshed after this interval. Must be positive (a negative value will never refresh). Should be less than 1 second. Default is 300 milliseconds.- See Also:
-
OSHI_UTIL_WMI_TIMEOUT
The WMI query timeout in milliseconds. Default is -1 (no timeout).- See Also:
-
OSHI_UTIL_PROC_PATH
The/procfilesystem location. Some containers enable alternate locations to provide container-level output in preference to system-level output. Default is/proc.- See Also:
-
OSHI_UTIL_SYS_PATH
The/sysfilesystem location. Some containers enable alternate locations to provide container-level output in preference to system-level output. Default is/sys.- See Also:
-
OSHI_UTIL_DEV_PATH
The/devfilesystem location. Some containers enable alternate locations to provide container-level output in preference to system-level output. Default is/dev.- See Also:
-
OSHI_PSEUDO_FILESYSTEM_TYPES
A comma-separated list of filesystem types to treat as pseudo-filesystems and exclude from file store listings. Seeoshi.propertiesfor the full default list.- See Also:
-
OSHI_NETWORK_FILESYSTEM_TYPES
A comma-separated list of filesystem types that are network-based and should be excluded from local-only file store listings. Default includesafs,cifs,smbfs,nfs,nfs4, and others.- See Also:
-
OSHI_OS_LINUX_ALLOWUDEV
Whether to use udev on Linux for loading hardware information such as USB devices, power sources, and disk information. Some details can be loaded via sysfs as a fallback, but others require udev. Default istrue.- See Also:
-
OSHI_OS_LINUX_ALLOWSYSTEMD
Whether to use systemd on Linux for loading session information when utmp is unavailable or deprecated. Set tofalseto fall back to file-based session parsing or thewhocommand. Default istrue.- See Also:
-
OSHI_OS_LINUX_PROCFS_LOGWARNING
Whether to log warnings when failing to read process information from the/procpseudo-filesystem on Linux. When running without elevated permissions, frequent errors reading process environment files are expected. Default isfalse.- See Also:
-
OSHI_OS_MAC_SYSCTL_LOGWARNING
Whether to log warnings when failing to read process information via sysctl on macOS. When running without elevated permissions, frequent errors reading process environment are expected. Default isfalse.- See Also:
-
OSHI_OS_WINDOWS_EVENTLOG
The name of the Windows System event log containing bootup event IDs 12 and 6005, used for a one-time calculation of system boot time that is consistent across process runs regardless of sleep/hibernate cycles. If set to the empty string, boot time is calculated by subtracting uptime from the current time (faster but less accurate). Default isSystem.- See Also:
-
OSHI_OS_WINDOWS_PROCSTATE_SUSPENDED
Whether to update the process state on Windows toSUSPENDEDif all its threads are suspended. This requires querying thread states and can significantly impact performance when querying process lists. Default isfalse.- See Also:
-
OSHI_OS_WINDOWS_COMMANDLINE_BATCH
Whether to perform WMI queries for command lines in a batch for all running processes. Individual WMI queries take about 50ms each while querying the entire process list takes about 200ms. Enable this if you regularly query command lines for more than a few processes. Default isfalse.- See Also:
-
OSHI_OS_WINDOWS_HKEYPERFDATA
Whether to attempt to fetch Windows performance counter data for processes and threads fromHKEY_PERFORMANCE_DATAin the registry. This is faster than the PDH API but more subject to registry corruption and counter deletion when changing language settings. Set tofalseto skip the registry check and use the API-recommended (but slower) performance counter API. Default istrue.- See Also:
-
OSHI_OS_WINDOWS_LEGACY_SYSTEM_COUNTERS
Whether to use the Legacy Processor performance counters for System CPU ticks instead of Processor Information (since Windows 7). Legacy counters are not processor-group aware and may give incorrect results on systems with more than 64 logical processors. Default isfalse.- See Also:
-
OSHI_OS_WINDOWS_LOADAVERAGE
Whether to start a daemon thread to provide load averages on Windows. While Windows does not natively provide this metric, the Processor Queue Length performance counter combined with recent processor usage provides a similar metric. Default isfalse.- See Also:
-
OSHI_OS_WINDOWS_CPU_UTILITY
Whether to use "Processor Utility" for System and per-processor CPU Load ticks (on Windows 8 and higher) to match CPU usage with the Windows Task Manager.By default, OSHI uses "Processor Time" which measures active and idle times, matching Unix-based systems and Windows 7 Task Manager. Setting this to
trueswitches to "Processor Utility" which measures work completed relative to nominal frequency. Because of features like Intel Turbo Boost and AMD Precision Boost, this value can exceed 100% (though Task Manager caps it). OSHI does not cap the value.For this calculation to produce meaningful data, the ticks must come from the same CentralProcessor instance and the first polling interval must be less than 7 minutes. Default is
false.- See Also:
-
OSHI_OS_WINDOWS_PERFDISK_DISABLED
Whether PerfDisk performance counters are disabled. If counters are intentionally disabled (e.g., for gaming performance) or the application does not need disk read/write/queue metrics, set totrueto skip querying and suppress log warnings. Default is unset (OSHI auto-detects from the registry).- See Also:
-
OSHI_OS_WINDOWS_PERFOS_DISABLED
Whether PerfOS performance counters are disabled. These counters are used for CPU ticks, swap file usage, page swaps, context switches, and interrupts. Set totrueto skip querying and suppress log warnings. Default is unset (OSHI auto-detects from the registry).- See Also:
-
OSHI_OS_WINDOWS_PERFPROC_DISABLED
Whether PerfProc performance counters are disabled. These counters are used for process and thread priority, time, I/O, and memory usage. Set totrueto skip querying and suppress log warnings. Default is unset (OSHI auto-detects from the registry).- See Also:
-
OSHI_OS_WINDOWS_PERF_DISABLE_ALL_ON_FAILURE
Whether to assume any performance counter failure means all counters will fail and revert to WMI backup. Default isfalse.- See Also:
-
OSHI_OS_UNIX_WHOCOMMAND
Whether to use the Posix-standardwhocommand for session information instead of native code. The native implementation (getutxent) is not thread safe; while OSHI synchronizes its own access, other OS code may access the same data structures. The command-line variant may use reentrant code on some platforms. Default isfalse.- See Also:
-
OSHI_OS_SOLARIS_ALLOWKSTAT2
Whether to allow use of the kstat2 API on Solaris 11.4+. The new API offers additional features but may have a file descriptor leak when parallel GC is in use. Set tofalseto always use the original kstat API. Default istrue.- See Also:
-
OSHI_OS_LINUX_PRIVILEGED_PREFIX
The command prefix to prepend for privileged command execution on Linux (e.g.,"sudo -n"for non-interactive sudo). This supports the Principle of Least Privilege by allowing fine-grained access to specific commands without running the entire application as root. The prefix is not applied when already running as root. Default is the empty string (no privilege escalation).- See Also:
-
OSHI_OS_LINUX_PRIVILEGED_ALLOWLIST
A comma-separated list of commands eligible for privilege escalation on Linux. Use full paths matching your sudoers configuration (e.g.,/usr/sbin/dmidecode) or bare names to match regardless of path. The allowlist should mirror theNOPASSWDentries in your sudoers file. Default is the empty string (no commands allowed).- See Also:
-
OSHI_OS_LINUX_PRIVILEGED_FILE_ALLOWLIST
A comma-separated list of file paths eligible for privileged read viasudo catfallback on Linux when normal file read fails due to permissions. Supports Java glob patterns (*,?,[abc]).Security warning: Take care when adding paths. Allowing privileged reads of sensitive files such as process environ files can expose credentials to unprivileged users. Default is the empty string (no files allowed).
- See Also:
-
-
Method Details
-
get
-
get
-
get
Get theintproperty associated with the given key.- Parameters:
key- The property keydef- The default value- Returns:
- The property value or the given default if not found
-
get
Get thedoubleproperty associated with the given key.- Parameters:
key- The property keydef- The default value- Returns:
- The property value or the given default if not found
-
get
Get thebooleanproperty associated with the given key.- Parameters:
key- The property keydef- The default value- Returns:
- The property value or the given default if not found
-
set
-
remove
Reset the given property to its default value.- Parameters:
key- The property key
-
clear
public static void clear()Clear the configuration. -
load
Load the givenPropertiesinto the global configuration.- Parameters:
properties- The new properties
-