Skip to content

Commit 1730a13

Browse files
pabloxxledsiper
authored andcommitted
in_podman_metrics: Fixed reading undefined PID
In case of not found pid file, it took a form of UINT64_MAX, after that plugin tried to read from it from proc. Fixed it. Also added alternative path for cgroupsv2 pid file. Signed-off-by: Paweł Cendrzak <[email protected]>
1 parent 69634a4 commit 1730a13

File tree

12 files changed

+20
-3
lines changed

12 files changed

+20
-3
lines changed

plugins/in_podman_metrics/podman_metrics_config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
#define V2_SYSFS_FILE_MEMORY_LIMIT "memory.max"
107107
#define V2_SYSFS_FILE_CPU_STAT "cpu.stat"
108108
#define V2_SYSFS_FILE_PIDS "cgroup.procs"
109+
#define V2_SYSFS_FILE_PIDS_ALT "containers/cgroup.procs"
109110

110111
/* Values used to construct counters/gauges names and descriptions */
111112
#define COUNTER_PREFIX "container"

plugins/in_podman_metrics/podman_metrics_data.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,12 @@ int fill_counters_with_sysfs_data_v1(struct flb_in_metrics *ctx)
331331
cnt->cpu_user = get_data_from_sysfs(ctx, cpu_path, V1_SYSFS_FILE_CPU_USER, NULL);
332332
cnt->cpu = get_data_from_sysfs(ctx, cpu_path, V1_SYSFS_FILE_CPU, NULL);
333333
pid = get_data_from_sysfs(ctx, systemd_path, V1_SYSFS_FILE_PIDS, NULL);
334-
if (pid) {
334+
if (pid && pid != UINT64_MAX) {
335335
get_net_data_from_proc(ctx, cnt, pid);
336336
}
337+
else {
338+
flb_plg_warn(ctx->ins, "Failed to collect PID for %s", cnt->name);
339+
}
337340
}
338341
return 0;
339342
}
@@ -364,9 +367,15 @@ int fill_counters_with_sysfs_data_v2(struct flb_in_metrics *ctx)
364367
cnt->cpu_user = get_data_from_sysfs(ctx, path, V2_SYSFS_FILE_CPU_STAT, STAT_KEY_CPU_USER);
365368
cnt->cpu = get_data_from_sysfs(ctx, path, V2_SYSFS_FILE_CPU_STAT, STAT_KEY_CPU);
366369
pid = get_data_from_sysfs(ctx, path, V2_SYSFS_FILE_PIDS, NULL);
367-
if (pid) {
370+
if (!pid || pid == UINT64_MAX) {
371+
pid = get_data_from_sysfs(ctx, path, V2_SYSFS_FILE_PIDS_ALT, NULL);
372+
}
373+
if (pid && pid != UINT64_MAX) {
368374
get_net_data_from_proc(ctx, cnt, pid);
369375
}
376+
else {
377+
flb_plg_warn(ctx->ins, "Failed to collect PID for %s", cnt->name);
378+
}
370379
}
371380
return 0;
372381
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
42
2+
73
3+
12

0 commit comments

Comments
 (0)