feat: add memory related stats

This commit is contained in:
Paul Pan 2024-03-13 17:58:33 +08:00
parent 25ba8d7076
commit d573c588b0

View File

@ -280,17 +280,31 @@ void dumpCgroupStats(nsjconf_t *nsjconf, const std::string &cgroup_path) {
return;
}
const auto resources = {"cpu.stat", "io.stat", "memory.stat"};
for (const auto &resource : resources) {
std::ifstream resource_file(cgroup_path + "/" + resource);
if (!resource_file.is_open()) {
const auto stats = {"cpu.stat", "io.stat", "memory.stat"};
for (const auto &res : stats) {
std::ifstream f(cgroup_path + "/" + res);
if (!f.is_open()) {
PLOG_W("Failed to open cgroup resource file '%s'",
(cgroup_path + "/" + resource).c_str());
(cgroup_path + "/" + res).c_str());
continue;
}
dump_file << resource_file.rdbuf();
dump_file << f.rdbuf();
dump_file << std::endl;
resource_file.close();
f.close();
}
const auto mem_stats = {"memory.peak", "memory.swap.peak"};
for (const auto &res : mem_stats) {
std::ifstream f(cgroup_path + "/" + res);
if (!f.is_open()) {
PLOG_W("Failed to open cgroup resource file '%s'",
(cgroup_path + "/" + res).c_str());
continue;
}
std::string line;
std::getline(f, line);
dump_file << res << ' ' << line << std::endl;
f.close();
}
dump_file.close();