From c67512ab317c0bdb32c31e9bf61b59bb65599c49 Mon Sep 17 00:00:00 2001 From: luffysong Date: Mon, 12 Jun 2023 17:57:11 +0800 Subject: [PATCH] processes: Do not post metrics from processes that are not running. Signed-off-by: sujankhadka Signed-off-by: tiozhang Signed-off-by: luffysong --- src/collectd.conf.in | 1 + src/collectd.conf.pod | 5 +++++ src/processes.c | 12 ++++++++++++ 3 files changed, 18 insertions(+) diff --git a/src/collectd.conf.in b/src/collectd.conf.in index 2a3cc9e2e..dbefc9cd6 100644 --- a/src/collectd.conf.in +++ b/src/collectd.conf.in @@ -1472,6 +1472,7 @@ # CollectMemoryMaps true # CollectDelayAccounting false # CollectSystemContextSwitch false +# SkipNonRunningProcess false # Process "name" # ProcessMatch "name" "regex" # diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index 6dccae446..3566605ce 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -8172,6 +8172,11 @@ Collect ctxt fields from /proc/stat in linux systems. Can be configured only outside the B and B blocks. +=item B I + +Skip submitting metrics for Zombie and non running processes. +Disabled by default. + =back The B, B, diff --git a/src/processes.c b/src/processes.c index fd460008e..6dda0368a 100644 --- a/src/processes.c +++ b/src/processes.c @@ -297,6 +297,7 @@ typedef struct procstat { bool report_maps_num; bool report_ctx_switch; bool report_delay; + bool skip_non_running_procs; struct procstat *next; struct procstat_entry_s *instances; @@ -310,6 +311,7 @@ static bool report_fd_num; static bool report_maps_num; static bool report_delay; static bool report_sys_ctxt_switch; +static bool skip_non_running_procs; #if HAVE_THREAD_INFO static mach_port_t port_host_self; @@ -381,6 +383,7 @@ static procstat_t *ps_list_register(const char *name, const char *regexp) { new->report_maps_num = report_maps_num; new->report_ctx_switch = report_ctx_switch; new->report_delay = report_delay; + new->skip_non_running_procs = skip_non_running_procs; #if HAVE_REGEX_H if (regexp != NULL) { @@ -680,6 +683,8 @@ static void ps_tune_instance(oconfig_item_t *ci, procstat_t *ps) { WARNING("processes plugin: The plugin has been compiled without support " "for the \"CollectDelayAccounting\" option."); #endif + } else if (strcasecmp(c->key, "SkipNonRunningProcess") == 0) { + cf_util_get_boolean(c, &ps->skip_non_running_procs); } else { ERROR("processes plugin: Option \"%s\" not allowed here.", c->key); } @@ -750,6 +755,8 @@ static int ps_config(oconfig_item_t *ci) { #endif } else if (strcasecmp(c->key, "CollectSystemContextSwitch") == 0) { cf_util_get_boolean(c, &report_sys_ctxt_switch); + } else if (strcasecmp(c->key, "SkipNonRunningProcess") == 0) { + cf_util_get_boolean(c, &skip_non_running_procs); } else { ERROR("processes plugin: The `%s' configuration option is not " "understood and will be ignored.", @@ -839,6 +846,11 @@ static void ps_submit_state(const char *state, double value) { /* submit info about specific process (e.g.: memory taken, cpu usage, etc..) */ static void ps_submit_proc_list(procstat_t *ps) { + if (ps->skip_non_running_procs && ps->num_lwp == 0) { + DEBUG("processes: Skip submit data from a non-running process %s", + ps->name); + return; + } value_list_t vl = VALUE_LIST_INIT; value_t values[2]; -- 2.39.5