Ad Widget

Collapse

Check if NFS mount exists

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PieterB
    Junior Member
    Zabbix Certified Specialist
    • Jul 2010
    • 25

    #1

    Check if NFS mount exists

    Recently we had some problems with failing NFS servers, and on our linux
    servers the mounts disappeared. I would like to check if a given
    NFS mount is still in good shape...

    Most posts I found mention using grep on the mount command,
    but is this a good solution?

    (http://www.zabbix.com/forum/showthread.php?t=20114)
  • jrprado
    Junior Member
    • Sep 2010
    • 28

    #2
    It was the only solution I found.

    Here is how my:
    Code:
    UserParameter = nfs[*], df | grep -c $1
    Returns 1 if it is mounted.
    Last edited by jrprado; 22-12-2010, 19:05.

    Comment

    • surreal
      Junior Member
      • Jan 2013
      • 2

      #3
      solution using "stat"

      hi,

      i had the same problem for quite a while. basicaly, i wanted to detect whether an NFS share was currently:
      1) mounted at a given mounting point
      2) responding

      my solution is the following command:

      stat -f <mountingpoint> | grep -o 'Type: [a-zA-Z0-9 \t]\+$' | grep -o ': [a-zA-Z0-9 \t]\+$' | grep -o '[a-zA-Z0-9]\+'

      this returns the type of the directory provided as mountingpoint. in case of an NFS mount it returns "nfs". i guess it could be made a little shorter using awk or sed

      the command can be used either with system.run or as a UserParameter.

      if 2) is not working, meaning the mounting point doesn't respond, the agent will hang and the server will show an error. don't set the rate too low (at least 60-120s) or you may get a lot of hanging zabbix agents if the NFS share doesn't respond.

      Comment

      • Stephen Wood
        Member
        • Feb 2012
        • 43

        #4
        Code:
        system.run[(test -d /mnt/nfs && echo 0) || echo 1]
        Set your triggers to alarm at 1. The test command returns true if the file exists and is a directory.

        If you want to check a static tile within the mounted directory that's just as easy:

        Code:
        system.run[(test -f /mnt/nfs/myfile && echo 0) || echo 1]

        Comment

        • surreal
          Junior Member
          • Jan 2013
          • 2

          #5
          test-ing for file existence

          this only works if you know at least one constantly present file on the NFS volume. it may also result in wrong results if the NFS volume is under heavy load and the response time exceeds the timeout of the zabbix agent (i usually use 3 seconds for that).

          from my experience, the "stat" call works better, as it only needs the mount point and results in fewer false positives.

          Comment

          • Stephen Wood
            Member
            • Feb 2012
            • 43

            #6
            test -d will assume your mount point stays the same, since it checks if it is a directory. I don't think either method has a serious advantage over the other, but this is the reason the "test" command was created.

            Comment

            • fvdhoeven
              Junior Member
              • Apr 2013
              • 11

              #7
              test Nope!

              test -d won't work. It tests if it is a directory. It doesn't care if it is a mount point or not. Even if the NFS is unmounted, the test -d still returns true.

              Use of stat or mount with a grep is the way to go. Maybe not the most elegant way, but it does the job.

              Comment

              • Wouter
                Junior Member
                • Nov 2015
                • 1

                #8
                This UserParameter (using timeout from recent coreutils):

                Code:
                UserParameter=nfs.mount_ok[*],timeout -s 9 10 stat -f -c '%T' '$1'  || echo STALE

                Comment

                Working...