[lug] Monitoring file descriptors

Ben Whaley bwhaley at gmail.com
Mon Jul 28 17:15:56 MDT 2008


Folks,

I had a CentOS box that was continually hanging every 2-3 days due to some
out of control process consuming all available file descriptors. I've done a
bunch of stuff now (patched, fixed config problems with various services,
etc) that may have helped, but I also wrote a bash one-liner to monitor
available file descriptors going forward. Thought somebody might find this
useful.

if [ `cat /proc/sys/fs/file-nr | awk '{ diff=$3 - $1; print diff }'` -lt
20000 ]; then echo "Low on file descriptors - `cat /proc/sys/fs/file-nr |
awk '{ diff=$3 - $1; print diff }'`" | mail -s "ftp1 file descriptors"
ben at atrust.com; fi

To break it down:

cat /proc/sys/fs/file-nr
- file-nr contains the number of file descriptors in use and the total
number available (the limit is adjustable through /etc/security/limits.conf
on a Red Hat-like system)

awk '{ diff=$3 - $1; print diff }'
- This prints the difference between the total number of available
descriptors and the number currently in use

- If the number available is less than 2,000 it alerts via email. I run it
out of cron every 5 minutes.

Just trying to get us back on topic ;) Can't we all just be friends?

- Ben
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lug.boulder.co.us/pipermail/lug/attachments/20080728/bf102439/attachment.html>


More information about the LUG mailing list