Interface CgroupInfo

All Known Implementing Classes:
LinuxCgroupInfo

@PublicApi @ThreadSafe public interface CgroupInfo
Represents cgroup (control group) information for containerized environments.

This interface provides access to resource limits and usage metrics for processes running in cgroups, supporting both cgroup v1 and v2.

Default implementations return sentinel values indicating that the process is not running in a containerized environment. Platform-specific implementations override these methods with actual cgroup data.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final long
    Standard default CPU period in microseconds.
    static final long
    Sentinel value for unlimited CPU quota or PIDs.
    static final double
    Sentinel value for unlimited effective CPUs.
    static final long
    Sentinel value for unlimited memory.
  • Method Summary

    Modifier and Type
    Method
    Description
    default long
    Returns the CPU period for the cgroup in microseconds.
    default long
    Returns the CPU quota for the cgroup in microseconds.
    default long
    Returns the total CPU usage for the cgroup in nanoseconds.
    default double
    Returns the effective number of CPUs available to the cgroup.
    default long
    Returns the memory limit for the cgroup in bytes.
    default long
    Returns the current memory usage for the cgroup in bytes.
    default long
    Returns the current number of PIDs in the cgroup.
    default long
    Returns the maximum number of PIDs allowed in the cgroup.
    default int
    Returns the cgroup version being used.
    default boolean
    Returns whether the current process is running in a containerized environment (cgroup).
  • Field Details

    • UNLIMITED

      static final long UNLIMITED
      Sentinel value for unlimited CPU quota or PIDs.
      See Also:
    • DEFAULT_CPU_PERIOD

      static final long DEFAULT_CPU_PERIOD
      Standard default CPU period in microseconds.
      See Also:
    • UNLIMITED_MEMORY

      static final long UNLIMITED_MEMORY
      Sentinel value for unlimited memory.
      See Also:
    • UNLIMITED_CPUS

      static final double UNLIMITED_CPUS
      Sentinel value for unlimited effective CPUs.
      See Also:
  • Method Details

    • isContainerized

      default boolean isContainerized()
      Returns whether the current process is running in a containerized environment (cgroup).
      Returns:
      true if running in a cgroup, false otherwise
    • getVersion

      default int getVersion()
      Returns the cgroup version being used.
      Returns:
      1 for cgroup v1, 2 for cgroup v2, or 0 if not in a cgroup
    • getCpuQuota

      default long getCpuQuota()
      Returns the CPU quota for the cgroup in microseconds.
      Returns:
      the CPU quota in microseconds, or UNLIMITED if unlimited
    • getCpuPeriod

      default long getCpuPeriod()
      Returns the CPU period for the cgroup in microseconds.
      Returns:
      the CPU period in microseconds, or DEFAULT_CPU_PERIOD as the standard default when not explicitly set
    • getCpuUsage

      default long getCpuUsage()
      Returns the total CPU usage for the cgroup in nanoseconds.
      Returns:
      the CPU usage in nanoseconds
    • getEffectiveCpus

      default double getEffectiveCpus()
      Returns the effective number of CPUs available to the cgroup.

      This is calculated as quota / period when a quota is set.

      Returns:
      the effective number of CPUs as a double, or UNLIMITED_CPUS if unlimited
    • getMemoryLimit

      default long getMemoryLimit()
      Returns the memory limit for the cgroup in bytes.
      Returns:
      the memory limit in bytes, or UNLIMITED_MEMORY if unlimited
    • getMemoryUsage

      default long getMemoryUsage()
      Returns the current memory usage for the cgroup in bytes.
      Returns:
      the memory usage in bytes
    • getPidLimit

      default long getPidLimit()
      Returns the maximum number of PIDs allowed in the cgroup.
      Returns:
      the PID limit, or UNLIMITED if unlimited
    • getPidCurrent

      default long getPidCurrent()
      Returns the current number of PIDs in the cgroup.
      Returns:
      the current PID count