diff --git a/src/probes/system_infos.probe/system_proc.meta b/src/probes/system_infos.probe/system_proc.meta index d18482949d9b108b7f9ed34acd9ecb5395b7a59f..755c4dbe5d6d2d04ab1d006fa46fce6437b8aff0 100644 --- a/src/probes/system_infos.probe/system_proc.meta +++ b/src/probes/system_infos.probe/system_proc.meta @@ -12,6 +12,11 @@ measurements: type: "key", name: "tgid", }, + { + description: "in container id of process", + type: "key", + name: "con_tgid", + }, { description: "process group id", type: "label", diff --git a/src/probes/system_infos.probe/system_procs.c b/src/probes/system_infos.probe/system_procs.c index b3f460931d70512495b677a430b15aec17a8f493..775e90d00e68ecde4c2cb1b8c4ed9cf033dadf09 100644 --- a/src/probes/system_infos.probe/system_procs.c +++ b/src/probes/system_infos.probe/system_procs.c @@ -405,6 +405,35 @@ out: return 0; } +static int get_proc_con_tgid(u32 pid, proc_info_t *proc_info){ + FILE *f = NULL; + char fname[PATH_LEN]; + char line[LINE_BUF_LEN]; + + snprintf(fname, sizeof(fname), "/proc/%u/task/%u/status", pid, pid); + + f = fopen(fname, "r"); + if (f == NULL){ + return -1; + } + + while (fgets(line, LINE_BUF_LEN, f) != NULL){ + if (strncmp(line, "NStgid:", 7) == 0){ + u32 host_pid, con_pid; + if (sscanf(line + 7, "%u %u", &host_pid, &con_pid) == 2){ + if (host_pid == pid){ + proc_info->con_tgid = con_pid; + fclose(f); + return 0; + } + } + } + } + + fclose(f); + return 0; +} + static int update_proc_infos(u32 pid, proc_info_t *proc_info) { int ret = 0; @@ -435,6 +464,12 @@ static int update_proc_infos(u32 pid, proc_info_t *proc_info) return -1; } + ret = get_proc_con_tgid(pid, proc_info); + if (ret < 0) { + DEBUG("[SYSTEM_PROC] failed to get container tgid info\n"); + return -1; + } + return 0; } @@ -459,9 +494,10 @@ static void output_proc_infos(proc_hash_t *one_proc, unsigned int period) (period * sys_clock_ticks) * FULL_PER; nprobe_fprintf(stdout, - "|%s|%lu|%d|%d|%u|%.2f|%llu|%llu|%u|%u|%llu|%llu|%llu|%lu|%lu|%lu|%lu|%lu|%lu|%lu|%lu|%llu|%llu|%llu|%llu|%llu|%llu|%llu|%llu|%llu|%llu|%llu|%.2f|%llu|%.2f|%.2f|%.2f|\n", + "|%s|%lu|%d|%d|%d|%u|%.2f|%llu|%llu|%u|%u|%llu|%llu|%llu|%lu|%lu|%lu|%lu|%lu|%lu|%lu|%lu|%llu|%llu|%llu|%llu|%llu|%llu|%llu|%llu|%llu|%llu|%llu|%.2f|%llu|%.2f|%.2f|%.2f|\n", METRICS_PROC_NAME, one_proc->key.pid, + one_proc->info.con_tgid, one_proc->info.pgid, one_proc->info.ppid, one_proc->info.fd_count, diff --git a/src/probes/system_infos.probe/system_procs.h b/src/probes/system_infos.probe/system_procs.h index dbe7a682c0c8aa60cd477f5e63df071791367bf1..395ba8c859f850edee2ac01f960ede6f172ac815 100644 --- a/src/probes/system_infos.probe/system_procs.h +++ b/src/probes/system_infos.probe/system_procs.h @@ -79,6 +79,7 @@ typedef struct { char comm[PROC_NAME_MAX]; int pgid; int ppid; + int con_tgid; u64 proc_start_time; // FROM same as proc_stat_min_flt u32 fd_count; // FROM '/usr/bin/ls -l /proc/[PID]/fd | wc -l' u32 max_fd_limit; // FROM 'cat /proc/[PID]/limits | grep -w "MAX open files"'