Ad Widget

Collapse

Exclude bind mounts (mount --bind) in filesystem discovery

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yves.vogl
    Junior Member
    • Feb 2016
    • 6

    #1

    Exclude bind mounts (mount --bind) in filesystem discovery

    Since Linux 2.4.0 it is possible to remount parts of the file hierarchy somewhere else.

    Steps to reproduce:

    Code:
    $ mkdir mount-1 mount-2
    $ mount --bind mount-1 mount-2
    $ echo "test" > mount-1/test.txt
    $ ls mount-*
    mount-1:
    test.txt
    
    mount-2:
    test.txt

    In /etc/mtab you'll see this:

    Code:
    /mnt/mount-1 /mnt/mount-2 none rw,bind 0 0
    This leads to duplicate triggers in the file system discovery. Maybe you should exclude bind mounts.

    Regards,
    Yves
  • kloczek
    Senior Member
    • Jun 2006
    • 1771

    #2
    Originally posted by yves.vogl
    Maybe you should exclude bind mounts.
    Maybe you should .. and you can do this using filters applying rules which one instance should not be monitored
    Generally both bind mount should not be monitored because source vol will be already monitored. So as solution you can apply filter off all bind mounts. Isn't it?

    PS. In my OS templates I have by default exclude monitoring everything mounted in directories below /mnt (as temporary mounted vols) and /net (all vols mounted from remote servers should be monitored on these servers).
    http://uk.linkedin.com/pub/tomasz-k%...zko/6/940/430/
    https://kloczek.wordpress.com/
    zapish - Zabbix API SHell binding https://github.com/kloczek/zapish
    My zabbix templates https://github.com/kloczek/zabbix-templates

    Comment

    • yves.vogl
      Junior Member
      • Feb 2016
      • 6

      #3
      I'd if I could ;-)

      How do you identify bind mounts?
      Last edited by yves.vogl; 22-06-2016, 16:57.

      Comment

      • yves.vogl
        Junior Member
        • Feb 2016
        • 6

        #4
        Looking at libs/zbxsysinfo/linux/diskspace.c#123 int VFS_FS_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result) it seems that instead of /etc/mtab or getmntent(3) the proc filesystem is used to get the mounted partitions.

        In /etc/mtab I can see if a mount point is „bound“:

        Code:
        /root/mount-1 /root/mount-2 none rw,bind 0 0
        In /proc/mounts this information is missing, isn't it?

        Code:
        /dev/mapper/vg_cinexus-LogVol01 /root/mount-2 ext4 rw,relatime,barrier=1,data=ordered 0 0

        And if I'm reading the sources correctly, #FSNAME and #FSTYPE for the example above will be:

        #FSNAME = /root/mount-2
        #FSTYPE = ext4

        So I'm curious how to filter bind mounts. Any ideas?

        Comment

        • yves.vogl
          Junior Member
          • Feb 2016
          • 6

          #5
          After reading the related libc code and this blogpost it seems to me that adding a feature to recognize "bind mounts" would mean to rely on information which shouldn't be available at all.

          So maybe the only thing we can do is to exclude those mount points by its path - individually for each host.

          Comment

          • kloczek
            Senior Member
            • Jun 2006
            • 1771

            #6
            Originally posted by yves.vogl
            After reading the related libc code and this blogpost it seems to me that adding a feature to recognize "bind mounts" would mean to rely on information which shouldn't be available at all.

            So maybe the only thing we can do is to exclude those mount points by its path - individually for each host.
            Just made your test:
            Code:
            mkdir -p /mnt/{1,2}; mount --bind 1 2; mount | grep /mnt/2
            /mnt/1 on /mnt/2 type none (rw,bind)
            But:
            Code:
            # /usr/sbin/zabbix_agentd -t vfs.fs.discovery
            vfs.fs.discovery                              [s|{"data":[{"{#FSNAME}":"/","{#FSTYPE}":"rootfs"},{"{#FSNAME}":"/proc","{#FSTYPE}":"proc"},{"{#FSNAME}":"/sys","{#FSTYPE}":"sysfs"},{"{#FSNAME}":"/dev","{#FSTYPE}":"devtmpfs"},{"{#FSNAME}":"/dev/pts","{#FSTYPE}":"devpts"},{"{#FSNAME}":"/dev/shm","{#FSTYPE}":"tmpfs"},{"{#FSNAME}":"/","{#FSTYPE}":"ext4"},{"{#FSNAME}":"/proc/bus/usb","{#FSTYPE}":"usbfs"},{"{#FSNAME}":"/proc/sys/fs/binfmt_misc","{#FSTYPE}":"binfmt_misc"},{"{#FSNAME}":"/mnt/2","{#FSTYPE}":"ext4"}]}]
            So this /mnt/2 mountpoint is listed as ext4 (source fs from which bind mount has been done in this case).
            Code:
            # (strace -e trace=open /usr/sbin/zabbix_agentd -t vfs.fs.discovery >/dev/null) 2>&1 | grep proc
            open("/proc/filesystems", O_RDONLY)     = 3
            open("/proc/mounts", O_RDONLY)          = 3
            So looks like zabbix agent is processing on Linux /proc/mounts to generate vfs.fs.discovery output. Problem is that using this procfs entry is not possible to identify bind mounts.
            Code:
            # cat /proc/mounts 
            rootfs / rootfs rw 0 0
            proc /proc proc rw,relatime 0 0
            sysfs /sys sysfs rw,relatime 0 0
            devtmpfs /dev devtmpfs rw,relatime,size=1951372k,nr_inodes=487843,mode=755 0 0
            devpts /dev/pts devpts rw,relatime,gid=5,mode=620,ptmxmode=000 0 0
            tmpfs /dev/shm tmpfs rw,relatime 0 0
            /dev/xvda1 / ext4 rw,relatime,barrier=1,data=ordered 0 0
            /proc/bus/usb /proc/bus/usb usbfs rw,relatime 0 0
            none /proc/sys/fs/binfmt_misc binfmt_misc rw,relatime 0 0
            /dev/xvda1 /mnt/2 ext4 rw,relatime,barrier=1,data=ordered 0 0
            However mount command shows clear output which allows say that some mountpoints are bind mounts.
            Code:
            # mount | grep mnt/2
            /mnt/1 on /mnt/2 type none (rw,bind)
            How it is possible to do? Hmm ..
            Code:
            # (strace -e trace=open mount >/dev/null)
            open("/etc/ld.so.cache", O_RDONLY)      = 3
            open("/lib64/libblkid.so.1", O_RDONLY)  = 3
            open("/lib64/libuuid.so.1", O_RDONLY)   = 3
            open("/lib64/libselinux.so.1", O_RDONLY) = 3
            open("/lib64/libsepol.so.1", O_RDONLY)  = 3
            open("/lib64/libc.so.6", O_RDONLY)      = 3
            open("/lib64/libdl.so.2", O_RDONLY)     = 3
            open("/proc/filesystems", O_RDONLY)     = 3
            open("/usr/lib/locale/locale-archive", O_RDONLY) = 3
            open("/dev/null", O_RDWR)               = 3
            open("/etc/mtab", O_RDONLY)             = 3
            Lets try ..
            Code:
            # grep /mnt/2 /etc/mtab 
            /mnt/1 /mnt/2 none rw,bind 0 0
            So mount is using /etc/mtab

            Problem on Linux is a bit tricky because on other OSes like Solaris loopback mount (equivalent of bind mount on Linux) is indicated as loopback fs and it is easy to identify such mountpints.

            Seems you have been right that it will be necessary to add ignore bind mounts ..
            Only because source bind mountpoints will be correctly listed in vfs.fs.discovery output unconditional filtering off these mounts theoretically should not break something.
            Please open jira ticket with this issue on https://support.zabbix.com/
            Last edited by kloczek; 23-06-2016, 11:38.
            http://uk.linkedin.com/pub/tomasz-k%...zko/6/940/430/
            https://kloczek.wordpress.com/
            zapish - Zabbix API SHell binding https://github.com/kloczek/zapish
            My zabbix templates https://github.com/kloczek/zabbix-templates

            Comment

            • yves.vogl
              Junior Member
              • Feb 2016
              • 6

              #7
              Thanks for your efforts. I've opened ZBX-10935 Filter bind mounts for VFS_FS_DISCOVERY on Linux

              Comment

              Working...