Skip to content

Commit

Permalink
cgroup v2 CPU & Memory stats for correct chart generation
Browse files Browse the repository at this point in the history
  • Loading branch information
gkhandake committed Oct 24, 2024
1 parent ddd963d commit f0c34e1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 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
16 changes: 7 additions & 9 deletions collector/src/cgroups_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,16 +192,14 @@ 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) {
for (auto entry : newEventsValues) {
auto prevValue = m_memory_prev_values.v2_events.find(entry.first);
if (prevValue != m_memory_prev_values.v2_events.end())
m_pOutput->plong(entry.first.c_str(), entry.second - prevValue->second);
}

// save new values for next sample:
m_memory_prev_values.v2_events = newEventsValues;
for (auto entry : newEventsValues) {
auto prevValue = m_memory_prev_values.v2_events.find(entry.first);
if (print && prevValue != m_memory_prev_values.v2_events.end())
m_pOutput->plong(entry.first.c_str(), entry.second - prevValue->second);
}

// save new values for next sample:
m_memory_prev_values.v2_events = newEventsValues;
}
} break;

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 f0c34e1

Please sign in to comment.