[lug] Re: Monitoring file descriptors

Ben Whaley bwhaley at gmail.com
Mon Jul 28 18:33:39 MDT 2008


NOTE: Apparently I have copy/paste issues. The one-liner should say
2,000, not 20,000.

 - Ben

On 7/28/08, Ben Whaley <bwhaley at gmail.com> wrote:
> 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
>

-- 
Sent from Gmail for mobile | mobile.google.com



More information about the LUG mailing list