Class LinuxCgroupInfo
java.lang.Object
oshi.software.common.os.linux.LinuxCgroupInfo
- All Implemented Interfaces:
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.
-
Field Summary
Fields inherited from interface CgroupInfo
DEFAULT_CPU_PERIOD, UNLIMITED, UNLIMITED_CPUS, UNLIMITED_MEMORY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongReturns the CPU period for the cgroup in microseconds.longReturns the CPU quota for the cgroup in microseconds.longReturns the total CPU usage for the cgroup in nanoseconds.longReturns the memory limit for the cgroup in bytes.longReturns the current memory usage for the cgroup in bytes.longReturns the current number of PIDs in the cgroup.longReturns the maximum number of PIDs allowed in the cgroup.intReturns the cgroup version being used.booleanReturns whether the current process is running in a containerized environment (cgroup).Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface CgroupInfo
getEffectiveCpus
-
Constructor Details
-
LinuxCgroupInfo
public LinuxCgroupInfo()Constructs a new LinuxCgroupInfo instance.
-
-
Method Details
-
isContainerized
public boolean isContainerized()Description copied from interface:CgroupInfoReturns whether the current process is running in a containerized environment (cgroup).- Specified by:
isContainerizedin interfaceCgroupInfo- Returns:
trueif running in a cgroup,falseotherwise
-
getVersion
public int getVersion()Description copied from interface:CgroupInfoReturns the cgroup version being used.- Specified by:
getVersionin interfaceCgroupInfo- Returns:
1for cgroup v1,2for cgroup v2, or0if not in a cgroup
-
getCpuQuota
public long getCpuQuota()Description copied from interface:CgroupInfoReturns the CPU quota for the cgroup in microseconds.- Specified by:
getCpuQuotain interfaceCgroupInfo- Returns:
- the CPU quota in microseconds, or
CgroupInfo.UNLIMITEDif unlimited
-
getCpuPeriod
public long getCpuPeriod()Description copied from interface:CgroupInfoReturns the CPU period for the cgroup in microseconds.- Specified by:
getCpuPeriodin interfaceCgroupInfo- Returns:
- the CPU period in microseconds, or
CgroupInfo.DEFAULT_CPU_PERIODas the standard default when not explicitly set
-
getCpuUsage
public long getCpuUsage()Description copied from interface:CgroupInfoReturns the total CPU usage for the cgroup in nanoseconds.- Specified by:
getCpuUsagein interfaceCgroupInfo- Returns:
- the CPU usage in nanoseconds
-
getMemoryLimit
public long getMemoryLimit()Description copied from interface:CgroupInfoReturns the memory limit for the cgroup in bytes.- Specified by:
getMemoryLimitin interfaceCgroupInfo- Returns:
- the memory limit in bytes, or
CgroupInfo.UNLIMITED_MEMORYif unlimited
-
getMemoryUsage
public long getMemoryUsage()Description copied from interface:CgroupInfoReturns the current memory usage for the cgroup in bytes.- Specified by:
getMemoryUsagein interfaceCgroupInfo- Returns:
- the memory usage in bytes
-
getPidLimit
public long getPidLimit()Description copied from interface:CgroupInfoReturns the maximum number of PIDs allowed in the cgroup.- Specified by:
getPidLimitin interfaceCgroupInfo- Returns:
- the PID limit, or
CgroupInfo.UNLIMITEDif unlimited
-
getPidCurrent
public long getPidCurrent()Description copied from interface:CgroupInfoReturns the current number of PIDs in the cgroup.- Specified by:
getPidCurrentin interfaceCgroupInfo- Returns:
- the current PID count
-