feat: add memory related stats
This commit is contained in:
parent
25ba8d7076
commit
d573c588b0
28
cgroup2.cc
28
cgroup2.cc
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user