Resource usage. Was: Headline - Linux misses Windows of opportunity

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



This is a script I use on all my machines.  Feel free to hack as required.

#!/bin/bash

# the warning limit for disk usage in %
DISK_USAGE=85

report()
{
         echo $*
#       logger $*
}

# check disk usage
full=0
for i in $(df | grep "/dev" | cut -c52-54) ; do
    if [ $i -ge $DISK_USAGE ] ; then
       full=1
    fi
done

if [ $full -gt 0 ] ; then
    report "Warning: disk nearing capacity on `hostname`"
    df
fi

# check in use file handles
count=$(cat /proc/sys/fs/file-nr | cut -f1)
limit=$(cat /proc/sys/fs/file-nr | cut -f3)

# do a simple check for 3 / 4 usage
count2=$(expr ${count} \* 4)
limit2=$(expr ${limit} \* 3)
if [ ${count2} -ge ${limit2} ] ; then
    report "Warning: file handles nearing limit on `hostname` ( ${count} 
out of ${limit} )"
fi


# check allocates semaphore arrays
eval `ipcs -ls | grep "max number of arrays" | tr -d " "`
eval `ipcs -us | grep "used arrays" | tr -d " "`
#echo $usedarrays
#echo $maxnumberofarrays

count=$usedarrays
limit=$maxnumberofarrays

# do a simple check for 3 / 4 usage
count2=$(expr ${count} \* 4)
limit2=$(expr ${limit} \* 3)
if [ ${count2} -ge ${limit2} ] ; then
    report "Warning: semaphore arrays nearing limit on `hostname` ( 
${count} out of ${limit} )"
fi

cat /proc/meminfo | grep ^Swap: | awk 'BEGIN {n = 3; d = 4} {total = $2 
/ 1024 ; used = $3 / 1024; if((total * n) < (used * d
)) { printf "Swap usage is over %d/%d\n", n, d}}'

Lamar Owen wrote:
> On Friday 30 September 2005 04:21, Dag Wieers wrote:
> 
>>On Thu, 29 Sep 2005, Lamar Owen wrote:
>>
>>>Oh, quick quiz: what happens to a CentOS box when you reboot after
>>>running out of disk space on the / filesystem?  You get a graphical login
>>>just fine, but then you can't login (you login, and it returns you to a
>>>login).  Not hard to fix, but very mysterious to the newbie.
> 
> 
>>I lost my Revelation password database because a disk-full condition
>>recently. An 2 week old backup didn't have some important passwords.
> 
> 
> Yeah, I lost some e-mail filters once that way, too, when my /home partition 
> filled up.  A 'high-water' mark utility probably has been written, and I know 
> logwatch can do periodic e-mails that, if you take the time to read them, can 
> give you advance notice of a disk full impending, but there are those times 
> when the disk might get full quite suddenly (particularly the /var partition 
> if something creates log spew (which, with SELinux, can happen extremely 
> quickly)).
> 
> 
>>BTW A tool that mails out when the disk is full is not a good solution...
> 
> 
> No kidding.


-- 
John Newbigin
Computer Systems Officer
Faculty of Information and Communication Technologies
Swinburne University of Technology
Melbourne, Australia
http://www.ict.swin.edu.au/staff/jnewbigin


[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux