Skip to content

Commit

Permalink
cgroup v2 CPU & memory stats for correct chart generation (#65)
Browse files Browse the repository at this point in the history
* fix reading of CPUSET in case cgroups v2 have been detected
* add stat.file and events.oom_kill stats to the list of stats to be charted
  • Loading branch information
gkhandake authored Oct 29, 2024
1 parent ddd963d commit 51c5901
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
8 changes: 6 additions & 2 deletions collector/src/cgroups_cpuacct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@

bool CMonitorCgroups::read_cpuset_cpus(std::string kernelPath, std::set<uint64_t>& cpus)
{
std::set<uint64_t> empty_set;
return read_integers_with_range_validation(kernelPath + "/cpuset.cpus", 0, INT32_MAX, cpus);
if (m_nCGroupsFound == CG_NONE)
return false;

std::string cpuset_path = kernelPath + ((m_nCGroupsFound == CG_VERSION2)? "/cpuset.cpus.effective" : "/cpuset.cpus");

return read_integers_with_range_validation(cpuset_path, 0, INT32_MAX, cpus);
}

bool CMonitorCgroups::read_cpuacct_line(FastFileReader& reader, std::vector<uint64_t>& valuesINT /* OUT */)
Expand Down
2 changes: 1 addition & 1 deletion collector/src/cgroups_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ void CMonitorCgroups::sample_memory(
case CG_VERSION2: {
key_value_map_t newEventsValues;
if (sample_flat_keyed_file(m_cgroup_memory_v2_events, allowedStatsNames, "events.", newEventsValues)) {
if (print) {
if (print) {
for (auto entry : newEventsValues) {
auto prevValue = m_memory_prev_values.v2_events.find(entry.first);
if (prevValue != m_memory_prev_values.v2_events.end())
Expand Down
2 changes: 2 additions & 0 deletions collector/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,8 @@ int CMonitorCollectorApp::run_main_loop()
charted_stats_from_cgroup_memory_v1.insert("failcnt");
// cgroups v2
charted_stats_from_cgroup_memory_v2.insert("stat.anon");
charted_stats_from_cgroup_memory_v2.insert("stat.file");
charted_stats_from_cgroup_memory_v2.insert("events.oom_kill");
}
// else: leave empty

Expand Down

0 comments on commit 51c5901

Please sign in to comment.