]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
processes: Do not post metrics from processes that are not running. 4121/head
authorluffysong <zsfz_one@163.com>
Mon, 12 Jun 2023 09:57:11 +0000 (17:57 +0800)
committerluffysong <zsfz_one@163.com>
Sun, 11 Aug 2024 17:25:16 +0000 (01:25 +0800)
Signed-off-by: sujankhadka <sujankhadka@didiglobal.com>
Signed-off-by: tiozhang <zyhtheonly@yeah.net>
Signed-off-by: luffysong <zsfz_one@163.com>
src/collectd.conf.in
src/collectd.conf.pod
src/processes.c

index 2a3cc9e2ea12794b14f8c6990c7d825adbda3f69..dbefc9cd66142d2a447fa5f6781ac2bdcf4660ac 100644 (file)
 #      CollectMemoryMaps true
 #      CollectDelayAccounting false
 #      CollectSystemContextSwitch false
+#      SkipNonRunningProcess false
 #      Process "name"
 #      ProcessMatch "name" "regex"
 #      <Process "collectd">
index 6dccae4464244c1b65bf886ef148a89c0761b02f..3566605ce7442e7c7a5deb9020db75b8546b9960 100644 (file)
@@ -8172,6 +8172,11 @@ Collect ctxt fields from /proc/stat in linux systems.
 Can be configured only outside the B<Process> and B<ProcessMatch>
 blocks.
 
+=item B<SkipNonRunningProcess> I<Boolean>
+
+Skip submitting metrics for Zombie and non running processes.
+Disabled by default.
+
 =back
 
 The B<CollectContextSwitch>, B<CollectDelayAccounting>,
index fd460008ed58402ac16739c752949cfe494770a1..6dda0368ae296bc204848b84392946e91d5ff7ec 100644 (file)
@@ -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];