Browse Source

Try to detect bind mounts (#14831)

* try to detect bind mounts

* minor grammar fix

* remove option, skip binds by default

* add check of mount_point length

* add a comment

* use root to compare

---------

Co-authored-by: Chris Akritidis <43294513+cakrit@users.noreply.github.com>
Emmanuel Vasilakis 1 year ago
parent
commit
89f22f056c

+ 2 - 0
collectors/diskspace.plugin/README.md

@@ -13,6 +13,8 @@ Simple patterns can be used to exclude mounts from showed statistics based on pa
 
 By default, Netdata will enable monitoring metrics only when they are not zero. If they are constantly zero they are ignored. Metrics that will start having values, after Netdata is started, will be detected and charts will be automatically added to the dashboard (a refresh of the dashboard is needed for them to appear though).
 
+Netdata will try to detect mounts that are duplicates (i.e. from the same device), or binds, and will not display charts for them, as the device is usually already monitored.
+
 To configure this plugin, you need to edit the configuration file `netdata.conf`. You can do so by using the `edit config` script.  
 
 > ### Info

+ 12 - 0
collectors/proc.plugin/proc_self_mountinfo.c

@@ -360,6 +360,18 @@ struct mountinfo *mountinfo_read(int do_statvfs) {
             else {
                 mi->st_dev = 0;
             }
+
+            //try to detect devices with same minor and major modes. Within these,
+            //the larger mount point is considered a bind.
+            struct mountinfo *mt;
+            for(mt = root; mt; mt = mt->next) {
+                if(unlikely(mt->major == mi->major && mt->minor == mi->minor && !(mi->flags & MOUNTINFO_IS_BIND))) {
+                    if(strlen(mi->root) < strlen(mt->root))
+                        mt->flags |= MOUNTINFO_IS_BIND;
+                    else
+                        mi->flags |= MOUNTINFO_IS_BIND;
+                }
+            }
         }
         else {
             mi->filesystem = NULL;