updates to support cgroupv2 as well

This commit is contained in:
Sichen Zhao 2023-02-02 22:19:29 -08:00
parent 63bfa19465
commit d4ca058643

View File

@ -68,6 +68,8 @@ AsynchronousMetrics::AsynchronousMetrics(
openFileIfExists("/sys/fs/cgroup/memory/memory.limit_in_bytes", cgroupmem_limit_in_bytes);
openFileIfExists("/sys/fs/cgroup/memory/memory.usage_in_bytes", cgroupmem_usage_in_bytes);
openFileIfExists("/sys/fs/cgroup/memory/memory.max", cgroupmem_v2_limit_in_bytes);
openFileIfExists("/sys/fs/cgroup/memory/memory.current", cgroupmem_v2_usage_in_bytes);
openSensors();
openBlockDevices();
@ -882,7 +884,7 @@ void AsynchronousMetrics::update(TimePoint update_time)
}
}
if (cgroupmem_limit_in_bytes && cgroupmem_usage_in_bytes)
if (cgroupmem_limit_in_bytes || cgroupmem_usage_in_bytes || cgroupmem_v2_limit_in_bytes || cgroupmem_v2_usage_in_bytes)
{
try {
cgroupmem_limit_in_bytes->rewind();
@ -894,6 +896,13 @@ void AsynchronousMetrics::update(TimePoint update_time)
readText(cgroup_mem_limit_in_bytes, *cgroupmem_limit_in_bytes);
readText(cgroup_mem_usage_in_bytes, *cgroupmem_usage_in_bytes);
if (!cgroup_mem_limit_in_bytes && !cgroup_mem_limit_in_bytes) {
cgroupmem_v2_limit_in_bytes->rewind();
cgroupmem_v2_usage_in_bytes->rewind();
readText(cgroup_mem_limit_in_bytes, *cgroupmem_v2_limit_in_bytes);
readText(cgroup_mem_usage_in_bytes, *cgroupmem_v2_usage_in_bytes);
}
if (cgroup_mem_limit_in_bytes && cgroup_mem_usage_in_bytes)
{
new_values["CgroupMemoryTotal"] = { cgroup_mem_limit_in_bytes, "The total amount of memory in cgroup, in bytes." };