Class GlobalConfig

java.lang.Object
oshi.util.GlobalConfig

@NotThreadSafe public final class GlobalConfig extends Object
The global configuration utility. See src/main/resources/oshi.properties for default values.

Configuration is resolved in the following precedence order (highest wins):

  1. set(String, Object) — programmatic, at runtime
  2. Java system properties (-Doshi.*)
  3. Environment variables (OSHI_*) — mapped by uppercasing and replacing dots with underscores
  4. External properties file (-Doshi.properties.file=/path/to/file)
  5. oshi.properties on 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.

  • Field Details

    • OSHI_UTIL_MEMOIZER_EXPIRATION

      public static final String 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

      public static final String OSHI_UTIL_WMI_TIMEOUT
      The WMI query timeout in milliseconds. Default is -1 (no timeout).
      See Also:
    • OSHI_UTIL_PROC_PATH

      public static final String OSHI_UTIL_PROC_PATH
      The /proc filesystem 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

      public static final String OSHI_UTIL_SYS_PATH
      The /sys filesystem 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

      public static final String OSHI_UTIL_DEV_PATH
      The /dev filesystem 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

      public static final String OSHI_PSEUDO_FILESYSTEM_TYPES
      A comma-separated list of filesystem types to treat as pseudo-filesystems and exclude from file store listings. See oshi.properties for the full default list.
      See Also:
    • OSHI_NETWORK_FILESYSTEM_TYPES

      public static final String 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 includes afs, cifs, smbfs, nfs, nfs4, and others.
      See Also:
    • OSHI_OS_LINUX_ALLOWUDEV

      public static final String 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 is true.
      See Also:
    • OSHI_OS_LINUX_ALLOWSYSTEMD

      public static final String OSHI_OS_LINUX_ALLOWSYSTEMD
      Whether to use systemd on Linux for loading session information when utmp is unavailable or deprecated. Set to false to fall back to file-based session parsing or the who command. Default is true.
      See Also:
    • OSHI_OS_LINUX_PROCFS_LOGWARNING

      public static final String OSHI_OS_LINUX_PROCFS_LOGWARNING
      Whether to log warnings when failing to read process information from the /proc pseudo-filesystem on Linux. When running without elevated permissions, frequent errors reading process environment files are expected. Default is false.
      See Also:
    • OSHI_OS_MAC_SYSCTL_LOGWARNING

      public static final String 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 is false.
      See Also:
    • OSHI_OS_WINDOWS_EVENTLOG

      public static final String 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 is System.
      See Also:
    • OSHI_OS_WINDOWS_PROCSTATE_SUSPENDED

      public static final String OSHI_OS_WINDOWS_PROCSTATE_SUSPENDED
      Whether to update the process state on Windows to SUSPENDED if all its threads are suspended. This requires querying thread states and can significantly impact performance when querying process lists. Default is false.
      See Also:
    • OSHI_OS_WINDOWS_COMMANDLINE_BATCH

      public static final String 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 is false.
      See Also:
    • OSHI_OS_WINDOWS_HKEYPERFDATA

      public static final String OSHI_OS_WINDOWS_HKEYPERFDATA
      Whether to attempt to fetch Windows performance counter data for processes and threads from HKEY_PERFORMANCE_DATA in the registry. This is faster than the PDH API but more subject to registry corruption and counter deletion when changing language settings. Set to false to skip the registry check and use the API-recommended (but slower) performance counter API. Default is true.
      See Also:
    • OSHI_OS_WINDOWS_LEGACY_SYSTEM_COUNTERS

      public static final String 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 is false.
      See Also:
    • OSHI_OS_WINDOWS_LOADAVERAGE

      public static final String 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 is false.
      See Also:
    • OSHI_OS_WINDOWS_CPU_UTILITY

      public static final String 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 true switches 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

      public static final String 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 to true to skip querying and suppress log warnings. Default is unset (OSHI auto-detects from the registry).
      See Also:
    • OSHI_OS_WINDOWS_PERFOS_DISABLED

      public static final String 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 to true to skip querying and suppress log warnings. Default is unset (OSHI auto-detects from the registry).
      See Also:
    • OSHI_OS_WINDOWS_PERFPROC_DISABLED

      public static final String 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 to true to 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

      public static final String 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 is false.
      See Also:
    • OSHI_OS_UNIX_WHOCOMMAND

      public static final String OSHI_OS_UNIX_WHOCOMMAND
      Whether to use the Posix-standard who command 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 is false.
      See Also:
    • OSHI_OS_SOLARIS_ALLOWKSTAT2

      public static final String 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 to false to always use the original kstat API. Default is true.
      See Also:
    • OSHI_OS_LINUX_PRIVILEGED_PREFIX

      public static final String 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

      public static final String 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 the NOPASSWD entries in your sudoers file. Default is the empty string (no commands allowed).
      See Also:
    • OSHI_OS_LINUX_PRIVILEGED_FILE_ALLOWLIST

      public static final String OSHI_OS_LINUX_PRIVILEGED_FILE_ALLOWLIST
      A comma-separated list of file paths eligible for privileged read via sudo cat fallback 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

      public static String get(String key)
      Get the property associated with the given key.
      Parameters:
      key - The property key
      Returns:
      The property value if it exists, or null otherwise
    • get

      public static String get(String key, String def)
      Get the String property associated with the given key.
      Parameters:
      key - The property key
      def - The default value
      Returns:
      The property value or the given default if not found
    • get

      public static int get(String key, int def)
      Get the int property associated with the given key.
      Parameters:
      key - The property key
      def - The default value
      Returns:
      The property value or the given default if not found
    • get

      public static double get(String key, double def)
      Get the double property associated with the given key.
      Parameters:
      key - The property key
      def - The default value
      Returns:
      The property value or the given default if not found
    • get

      public static boolean get(String key, boolean def)
      Get the boolean property associated with the given key.
      Parameters:
      key - The property key
      def - The default value
      Returns:
      The property value or the given default if not found
    • set

      public static void set(String key, Object val)
      Set the given property, overwriting any existing value. If the given value is null, the property is removed.
      Parameters:
      key - The property key
      val - The new value
    • remove

      public static void remove(String key)
      Reset the given property to its default value.
      Parameters:
      key - The property key
    • clear

      public static void clear()
      Clear the configuration.
    • load

      public static void load(Properties properties)
      Load the given Properties into the global configuration.
      Parameters:
      properties - The new properties