#! /bin/sh### ZFS health check script for monit.## Original script from:## Calomel.org## https://calomel.org/zfs_health_check_script.html## ParametersmaxCapacity=$1 # in percentagesusage="Usage: $0 maxCapacityInPercentages\n"if [ ! "${maxCapacity}" ]; then printf "Missing arguments\n" printf "${usage}" exit 1fi# Output for monit user interfaceprintf "==== ZPOOL STATUS ====\n"printf "$(/sbin/zpool status)"printf "\n\n==== ZPOOL LIST ====\n"printf "%s\n" "$(/sbin/zpool list)"# Health - Check if all zfs volumes are in good condition. We are looking for# any keyword signifying a degraded or broken array.condition=$(/sbin/zpool status | grep -E 'DEGRADED|FAULTED|OFFLINE|UNAVAIL|REMOVED|FAIL|DESTROYED|corrupt|cannot|unrecover')if [ "${condition}" ]; then printf "\n==== ERROR ====\n" printf "One of the pools is in one of these statuses: DEGRADED|FAULTED|OFFLINE|UNAVAIL|REMOVED|FAIL|DESTROYED|corrupt|cannot|unrecover!\n" printf "$condition" exit 1fi# Capacity - Make sure the pool capacity is below 80% for best performance. The# percentage really depends on how large your volume is. If you have a 128GB# SSD then 80% is reasonable. If you have a 60TB raid-z2 array then you can# probably set the warning closer to 95%.## ZFS uses a copy-on-write scheme. The file system writes new data to# sequential free blocks first and when the uberblock has been updated the new# inode pointers become valid. This method is true only when the pool has# enough free sequential blocks. If the pool is at capacity and space limited,# ZFS will be have to randomly write blocks. This means ZFS can not create an# optimal set of sequential writes and write performance is severely impacted.capacity=$(/sbin/zpool list -H -o capacity | cut -d'%' -f1)for line in ${capacity} do if [ $line -ge $maxCapacity ]; then printf "\n==== ERROR ====\n" printf "One of the pools has reached it's max capacity!" exit 1 fi done# Errors - Check the columns for READ, WRITE and CKSUM (checksum) drive errors# on all volumes and all drives using "zpool status". If any non-zero errors# are reported an email will be sent out. You should then look to replace the# faulty drive and run "zpool scrub" on the affected volume after resilvering.errors=$(/sbin/zpool status | grep ONLINE | grep -v state | awk '{print $3 $4 $5}' | grep -v 000)if [ "${errors}" ]; then printf "\n==== ERROR ====\n" printf "One of the pools contains errors!" printf "$errors" exit 1fi# Finish - If we made it here then everything is fineexit 0
Error monit 'zfs_monit' failed to execute '/usr/local/bin/ZFS_monit.sh 80' -- No such file or directory