Class LinuxCgroupInfo

java.lang.Object
oshi.software.common.os.linux.LinuxCgroupInfo
All Implemented Interfaces:
CgroupInfo

@ThreadSafe public class LinuxCgroupInfo extends Object implements CgroupInfo
Linux implementation of CgroupInfo supporting both cgroup v2 and v1.

This implementation detects the cgroup version and reads resource limits and usage from the appropriate cgroup filesystem paths. Limit values are memoized while usage values are read fresh on each call.

Container detection (isContainerized()) checks for known container markers such as /.dockerenv, and cgroup paths containing /docker/, /kubepods/, /lxc/, etc.

  • Constructor Details

    • LinuxCgroupInfo

      public LinuxCgroupInfo()
      Constructs a new LinuxCgroupInfo instance.
  • Method Details

    • isContainerized

      public boolean isContainerized()
      Description copied from interface: CgroupInfo
      Returns whether the current process is running in a containerized environment (cgroup).
      Specified by:
      isContainerized in interface CgroupInfo
      Returns:
      true if running in a cgroup, false otherwise
    • getVersion

      public int getVersion()
      Description copied from interface: CgroupInfo
      Returns the cgroup version being used.
      Specified by:
      getVersion in interface CgroupInfo
      Returns:
      1 for cgroup v1, 2 for cgroup v2, or 0 if not in a cgroup
    • getCpuQuota

      public long getCpuQuota()
      Description copied from interface: CgroupInfo
      Returns the CPU quota for the cgroup in microseconds.
      Specified by:
      getCpuQuota in interface CgroupInfo
      Returns:
      the CPU quota in microseconds, or CgroupInfo.UNLIMITED if unlimited
    • getCpuPeriod

      public long getCpuPeriod()
      Description copied from interface: CgroupInfo
      Returns the CPU period for the cgroup in microseconds.
      Specified by:
      getCpuPeriod in interface CgroupInfo
      Returns:
      the CPU period in microseconds, or CgroupInfo.DEFAULT_CPU_PERIOD as the standard default when not explicitly set
    • getCpuUsage

      public long getCpuUsage()
      Description copied from interface: CgroupInfo
      Returns the total CPU usage for the cgroup in nanoseconds.
      Specified by:
      getCpuUsage in interface CgroupInfo
      Returns:
      the CPU usage in nanoseconds
    • getMemoryLimit

      public long getMemoryLimit()
      Description copied from interface: CgroupInfo
      Returns the memory limit for the cgroup in bytes.
      Specified by:
      getMemoryLimit in interface CgroupInfo
      Returns:
      the memory limit in bytes, or CgroupInfo.UNLIMITED_MEMORY if unlimited
    • getMemoryUsage

      public long getMemoryUsage()
      Description copied from interface: CgroupInfo
      Returns the current memory usage for the cgroup in bytes.
      Specified by:
      getMemoryUsage in interface CgroupInfo
      Returns:
      the memory usage in bytes
    • getPidLimit

      public long getPidLimit()
      Description copied from interface: CgroupInfo
      Returns the maximum number of PIDs allowed in the cgroup.
      Specified by:
      getPidLimit in interface CgroupInfo
      Returns:
      the PID limit, or CgroupInfo.UNLIMITED if unlimited
    • getPidCurrent

      public long getPidCurrent()
      Description copied from interface: CgroupInfo
      Returns the current number of PIDs in the cgroup.
      Specified by:
      getPidCurrent in interface CgroupInfo
      Returns:
      the current PID count