@@ -38,7 +38,17 @@ if [ -f /sys/fs/cgroup/cgroup.controllers ]; then
3838 print_metric " cgroup v2 memory.events oom_kill" " $( (grep -E ' ^oom_kill\\s' /sys/fs/cgroup/memory.events | cut -d' ' -f2) 2> /dev/null || echo ' not found' ) "
3939 print_metric " cgroup v2 memory.events high" " $( (grep -E ' ^high\\s' /sys/fs/cgroup/memory.events | cut -d' ' -f2) 2> /dev/null || echo ' not found' ) "
4040 fi
41- elif [ -d " /sys/fs/cgroup/memory" ]; then
41+
42+ # CPU metrics
43+ print_metric " cgroup v2 cpu.max" " $( cat_file /sys/fs/cgroup/cpu.max) "
44+ print_metric " cgroup v2 cpu.nr_throttled" " $( (grep -E " ^nr_throttled[[:space:]]+" /sys/fs/cgroup/cpu.stat | cut -d' ' -f2) 2> /dev/null || echo ' not found' ) "
45+ print_metric " cgroup v2 cpu.throttled_usec" " $( (grep -E " ^throttled_usec[[:space:]]+" /sys/fs/cgroup/cpu.stat | cut -d' ' -f2) 2> /dev/null || echo ' not found' ) "
46+ print_metric " cgroup v2 cpu.usage_usec" " $( (grep -E " ^usage_usec[[:space:]]+" /sys/fs/cgroup/cpu.stat | cut -d' ' -f2) 2> /dev/null || echo ' not found' ) "
47+ if [ -f /sys/fs/cgroup/cpu.pressure ]; then # cpu.pressure might not exist on older kernels/setups
48+ print_metric " cgroup v2 cpu.pressure" " $( cat_file /sys/fs/cgroup/cpu.pressure) "
49+ fi
50+
51+ elif [ -d " /sys/fs/cgroup/memory" ]; then # Assuming if memory cgroup v1 exists, cpu might too
4252 # cgroup v1
4353 # Note: In cgroup v1, memory stats are typically found under /sys/fs/cgroup/memory/
4454 # The specific path might vary if inside a nested cgroup.
@@ -47,6 +57,24 @@ elif [ -d "/sys/fs/cgroup/memory" ]; then
4757 print_metric " cgroup v1 memory.limit_in_bytes" " $( cat_file /sys/fs/cgroup/memory/memory.limit_in_bytes) "
4858 print_metric " cgroup v1 memory.failcnt" " $( cat_file /sys/fs/cgroup/memory/memory.failcnt) "
4959 print_metric " cgroup v1 memory.max_usage_in_bytes" " $( cat_file /sys/fs/cgroup/memory/memory.max_usage_in_bytes) "
60+
61+ # Throttling stats from /sys/fs/cgroup/cpu/cpu.stat
62+ if [ -f /sys/fs/cgroup/cpu/cpu.stat ]; then
63+ print_metric " cgroup v1 cpu.nr_throttled" " $( (grep -E " ^nr_throttled[[:space:]]+" /sys/fs/cgroup/cpu/cpu.stat | cut -d' ' -f2) 2> /dev/null || echo ' not found' ) "
64+ print_metric " cgroup v1 cpu.throttled_time_ns" " $( (grep -E " ^throttled_time[[:space:]]+" /sys/fs/cgroup/cpu/cpu.stat | cut -d' ' -f2) 2> /dev/null || echo ' not found' ) "
65+ else
66+ # Print not found for these specific metrics if cpu.stat is missing, to avoid ambiguity
67+ print_metric " cgroup v1 cpu.nr_throttled" " not found (cpu.stat)"
68+ print_metric " cgroup v1 cpu.throttled_time_ns" " not found (cpu.stat)"
69+ fi
70+ # CPU Quota settings from /sys/fs/cgroup/cpu/
71+ print_metric " cgroup v1 cpu.cfs_period_us" " $( cat_file /sys/fs/cgroup/cpu/cpu.cfs_period_us) "
72+ print_metric " cgroup v1 cpu.cfs_quota_us" " $( cat_file /sys/fs/cgroup/cpu/cpu.cfs_quota_us) "
73+ # CPU usage from /sys/fs/cgroup/cpuacct/ (usually same hierarchy as cpu)
74+ print_metric " cgroup v1 cpuacct.usage_ns" " $( cat_file /sys/fs/cgroup/cpuacct/cpuacct.usage) "
75+ print_metric " cgroup v1 cpuacct.usage_user_ns" " $( cat_file /sys/fs/cgroup/cpuacct/cpuacct.usage_user) "
76+ print_metric " cgroup v1 cpuacct.usage_sys_ns" " $( cat_file /sys/fs/cgroup/cpuacct/cpuacct.usage_sys) "
77+
5078else
5179 printf " cgroup memory paths not found. Neither cgroup v2 controller file nor cgroup v1 memory directory detected.\n"
5280fi
0 commit comments