Interface CgroupInfo
- All Known Implementing Classes:
LinuxCgroupInfo
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
FieldsModifier and TypeFieldDescriptionstatic final longStandard default CPU period in microseconds.static final longSentinel value for unlimited CPU quota or PIDs.static final doubleSentinel value for unlimited effective CPUs.static final longSentinel value for unlimited memory. -
Method Summary
Modifier and TypeMethodDescriptiondefault longReturns the CPU period for the cgroup in microseconds.default longReturns the CPU quota for the cgroup in microseconds.default longReturns the total CPU usage for the cgroup in nanoseconds.default doubleReturns the effective number of CPUs available to the cgroup.default longReturns the memory limit for the cgroup in bytes.default longReturns the current memory usage for the cgroup in bytes.default longReturns the current number of PIDs in the cgroup.default longReturns the maximum number of PIDs allowed in the cgroup.default intReturns the cgroup version being used.default booleanReturns whether the current process is running in a containerized environment (cgroup).
-
Field Details
-
UNLIMITED
static final long UNLIMITEDSentinel value for unlimited CPU quota or PIDs.- See Also:
-
DEFAULT_CPU_PERIOD
static final long DEFAULT_CPU_PERIODStandard default CPU period in microseconds.- See Also:
-
UNLIMITED_MEMORY
static final long UNLIMITED_MEMORYSentinel value for unlimited memory.- See Also:
-
UNLIMITED_CPUS
static final double UNLIMITED_CPUSSentinel 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:
trueif running in a cgroup,falseotherwise
-
getVersion
default int getVersion()Returns the cgroup version being used.- Returns:
1for cgroup v1,2for cgroup v2, or0if not in a cgroup
-
getCpuQuota
default long getCpuQuota()Returns the CPU quota for the cgroup in microseconds.- Returns:
- the CPU quota in microseconds, or
UNLIMITEDif unlimited
-
getCpuPeriod
default long getCpuPeriod()Returns the CPU period for the cgroup in microseconds.- Returns:
- the CPU period in microseconds, or
DEFAULT_CPU_PERIODas 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 / periodwhen a quota is set.- Returns:
- the effective number of CPUs as a double, or
UNLIMITED_CPUSif unlimited
-
getMemoryLimit
default long getMemoryLimit()Returns the memory limit for the cgroup in bytes.- Returns:
- the memory limit in bytes, or
UNLIMITED_MEMORYif 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
UNLIMITEDif unlimited
-
getPidCurrent
default long getPidCurrent()Returns the current number of PIDs in the cgroup.- Returns:
- the current PID count
-