Last active
December 10, 2015 20:28
-
-
Save bdossantos/4487826 to your computer and use it in GitHub Desktop.
Check number of opened files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Check number of opened files | |
if [ $# != 2 ]; then | |
echo "Syntax: check_max_open_files <warn percent> <crit percent>" | |
echo | |
echo "Example: check_max_open_files 75 90" | |
exit 3 | |
fi | |
opened_files=$(lsof | wc -l) | |
max_open_files=$(cat /proc/sys/fs/file-max) | |
if [ -z $opened_files ] || [ -z $max_open_files ]; then | |
echo "ERROR - Can't find opened_files / max_open_files" | |
exit 3 | |
fi | |
warn=$(expr $max_open_files \* $1 \/ 100) | |
crit=$(expr $max_open_files \* $2 \/ 100) | |
if [ $opened_files -gt $crit ]; then | |
echo "CRITICAL - $opened_files / $max_open_files" | |
exit 2 | |
elif [ $opened_files -gt $warn -a $opened_files -lt $crit ]; then | |
echo "WARNING - $opened_files / $max_open_files" | |
exit 1 | |
elif [ $opened_files -lt $warn ]; then | |
echo "OK - $opened_files / $max_open_files" | |
exit 0 | |
fi | |
echo "UNKNOWN - Error" | |
exit 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment