]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
LogOnce option for df plugin 2910/head
authorthemylogin <themylogin@gmail.com>
Mon, 27 Aug 2018 16:25:04 +0000 (19:25 +0300)
committerthemylogin <themylogin@gmail.com>
Sun, 1 Mar 2020 12:29:27 +0000 (13:29 +0100)
Enabling LogOnce true option in df plugin reduces syslog spam when stat
constantly fails for any of the mounted partitions.

src/collectd.conf.in
src/collectd.conf.pod
src/df.c
src/utils/ignorelist/ignorelist.c
src/utils/ignorelist/ignorelist.h

index 9e30358b59660981dad6f3a67f10421a74c8dba0..007f80eff8343d2cf91a288084b56fa4175a0b48 100644 (file)
 #      MountPoint "/home"
 #      FSType "ext3"
 #      IgnoreSelected false
+#      LogOnce false
 #      ReportByDevice false
 #      ReportInodes false
 #      ValuesAbsolute true
index 7e761b45c0c7e159ffdfdeab49c49775ca8027ff..9ef529afa91a020b896d08dc3b407e7f0dc6c624 100644 (file)
@@ -2745,6 +2745,10 @@ match any one of the criteria are collected. By default only selected
 partitions are collected if a selection is made. If no selection is configured
 at all, B<all> partitions are selected.
 
+=item B<LogOnce> B<false>|B<false>
+
+Only log stat() errors once.
+
 =item B<ReportByDevice> B<true>|B<false>
 
 Report using the device name rather than the mountpoint. i.e. with this I<false>,
index 5b3fbd28edcc0f58c6db34bc90a53391c3675f55..60f20d3e884f350fc3a119f6a212176f797711f1 100644 (file)
--- a/src/df.c
+++ b/src/df.c
 #endif
 
 static const char *config_keys[] = {
-    "Device",         "MountPoint",   "FSType",         "IgnoreSelected",
-    "ReportByDevice", "ReportInodes", "ValuesAbsolute", "ValuesPercentage"};
+    "Device",         "MountPoint",       "FSType",
+    "IgnoreSelected", "ReportByDevice",   "ReportInodes",
+    "ValuesAbsolute", "ValuesPercentage", "LogOnce"};
 static int config_keys_num = STATIC_ARRAY_SIZE(config_keys);
 
 static ignorelist_t *il_device;
 static ignorelist_t *il_mountpoint;
 static ignorelist_t *il_fstype;
+static ignorelist_t *il_errors;
 
 static bool by_device;
 static bool report_inodes;
 static bool values_absolute = true;
 static bool values_percentage;
+static bool log_once;
 
 static int df_init(void) {
   if (il_device == NULL)
@@ -67,6 +70,8 @@ static int df_init(void) {
     il_mountpoint = ignorelist_create(1);
   if (il_fstype == NULL)
     il_fstype = ignorelist_create(1);
+  if (il_errors == NULL)
+    il_errors = ignorelist_create(1);
 
   return 0;
 }
@@ -122,6 +127,13 @@ static int df_config(const char *key, const char *value) {
     else
       values_percentage = false;
 
+    return 0;
+  } else if (strcasecmp(key, "LogOnce") == 0) {
+    if (IS_TRUE(value))
+      log_once = true;
+    else
+      log_once = false;
+
     return 0;
   }
 
@@ -203,8 +215,17 @@ static int df_read(void) {
       continue;
 
     if (STATANYFS(mnt_ptr->dir, &statbuf) < 0) {
-      ERROR(STATANYFS_STR "(%s) failed: %s", mnt_ptr->dir, STRERRNO);
+      if (log_once == false || ignorelist_match(il_errors, mnt_ptr->dir) == 0) {
+        if (log_once == true) {
+          ignorelist_add(il_errors, mnt_ptr->dir);
+        }
+        ERROR(STATANYFS_STR "(%s) failed: %s", mnt_ptr->dir, STRERRNO);
+      }
       continue;
+    } else {
+      if (log_once == true) {
+        ignorelist_remove(il_errors, mnt_ptr->dir);
+      }
     }
 
     if (!statbuf.f_blocks)
index 9e1b9e3a2ed0c0519f3ecc3c0b1fdef20f8d91a1..f0298e8dccde8ac5d5f2c7ff20596ae578ef21ba 100644 (file)
@@ -278,6 +278,37 @@ int ignorelist_add(ignorelist_t *il, const char *entry) {
   return ignorelist_append_string(il, entry);
 } /* int ignorelist_add (ignorelist_t *il, const char *entry) */
 
+/*
+ * remove entry from ignorelist_t
+ * return 0 for success
+ */
+int ignorelist_remove(ignorelist_t *il, const char *entry) {
+  /* if no entries, nothing to remove */
+  if ((il == NULL) || (il->head == NULL))
+    return (1);
+
+  if ((entry == NULL) || (strlen(entry) == 0))
+    return (1);
+
+  /* traverse list and check entries */
+  for (ignorelist_item_t *prev = NULL, *traverse = il->head; traverse != NULL;
+       prev = traverse, traverse = traverse->next) {
+    if (traverse->smatch != NULL && strcmp(traverse->smatch, entry) == 0) {
+      if (prev == NULL) {
+        il->head = traverse->next;
+      } else {
+        prev->next = traverse->next;
+      }
+      sfree(traverse->smatch);
+      traverse->smatch = NULL;
+      sfree(traverse);
+      return (0);
+    }
+  } /* for traverse */
+
+  return (1);
+} /* int ignorelist_remove (ignorelist_t *il, const char *entry) */
+
 /*
  * check list for entry
  * return 1 for ignored entry
index a7fa86d5482caa71f4b1028430dc3c8a017bb24e..5b8d3a67ab661d74b8399f3987f5c6957a984c65 100644 (file)
@@ -60,6 +60,12 @@ void ignorelist_set_invert(ignorelist_t *il, int invert);
  */
 int ignorelist_add(ignorelist_t *il, const char *entry);
 
+/*
+ * remote entry from ignorelist_t
+ * returns zero on success, non-zero upon failure.
+ */
+int ignorelist_remove(ignorelist_t *il, const char *entry);
+
 /*
  * check list for entry
  * return 1 for ignored entry