Skip to content

Commit

Permalink
fix(bpf_collector): fix command name in case of kernel processes
Browse files Browse the repository at this point in the history
  if the cgroupID for the pid is 1, it is considered as kernel process
  and bpf cpu time for each such process is aggregated under the same
  ProcessStat

  But the command which shows up in metric is from the first pid which
  created the entry in ProcessStats. It could be a kworker, or
  rcu_preempt, or some other kernel process. Which is misleading because
  it shows that process consuming most of bpf cpu time.

  This commit:
  - uses "kernel_processes" as the command for pid 1 kernel processes
  - sets the pid as 1 instead of the pid of the process that created the
    entry

Signed-off-by: Vimal Kumar <[email protected]>
  • Loading branch information
vimalk78 committed Oct 9, 2024
1 parent 99b1f94 commit 908db28
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,19 @@ func UpdateProcessBPFMetrics(bpfExporter bpf.Exporter, processStats map[uint64]*
}

mapKey := ct.Pid
process := comm
if ct.CgroupId == 1 && config.EnabledEBPFCgroupID() {
// we aggregate all kernel process to minimize overhead
// all kernel process has cgroup id as 1 and pid 1 is also a kernel process
mapKey = 1
process = "kernel_processes"
}

bpfSupportedMetrics := bpfExporter.SupportedMetrics()
var ok bool
var pStat *stats.ProcessStats
if pStat, ok = processStats[mapKey]; !ok {
pStat = stats.NewProcessStats(ct.Pid, ct.CgroupId, containerID, vmID, comm, bpfSupportedMetrics)
pStat = stats.NewProcessStats(mapKey, ct.CgroupId, containerID, vmID, process, bpfSupportedMetrics)
processStats[mapKey] = pStat
} else if pStat.Command == "" {
pStat.Command = comm
Expand Down

0 comments on commit 908db28

Please sign in to comment.