Search code examples
consul

Consul - Alert if drive is full


In the demo of consul, there are checks for disk utilization and memory utilization. enter image description here

http://demo.consul.io/ui/#/ams2/nodes/ams2-server-1

How could you write a configuration to do what the demo shows? Warning at 10% and critical erros at 5% ?

Here is what I am trying

{
  "check": {
     "name": "Disk Util",
     "script": "disk_util=$(df -k | grep '/dev/sda1' | awk '{print $5}' | sed 's/[^0-9]*//g' ) | if [ $disk_util >  90 ] ; then echo 'Disk /dev/sda above 90% full' && exit 1; elif [ $disk_util > 80 ] ; then echo 'Disk /dev/sda above 80%' && exit 3;  else exit 0; fi",
     "interval": "2m"
     }
}

Here is the same script, but more human readable

disk_util=$(df -k | grep '/dev/sda1' | awk '{print $5}' | sed 's/[^0-9]*//g' ) | 
if [ $disk_util >  90 ] 
 then echo 'Disk /dev/sda above 90% full' && exit 1
elif [ $disk_util > 80 ] 
 then echo 'Disk /dev/sda above 80%' && exit 3
else exit 0; fi

It seems like the check is working, but it doesn't print out any text. How can I verify this is working, and print output?

enter image description here


Solution

    1. The output that you are seeing is produced by Nagios plugin check_disk (https://www.monitoring-plugins.org/doc/man/check_disk.html)
    2. The "Output" field gets populated by stdout of the check. Your check runs cleanly and produces no output. So you see nothing.
    3. To add some notes just add a "notes" field in the check definition as outlined in the documentation: https://www.consul.io/docs/agent/checks.html

    Your check json file would look something like this:

    {
      "check": {
        "name": "disks",
        "notes": "Critical 5%, warning 10% free",
        "script": "/path/to/check_disk -w 10% -c 5%",
        "interval": "2m"
      }
    }