Sunday, October 24, 2010

How to check server's resource usage?

You can use following script :

======
root@magneto [/var/log]# cat resusage.sh
#!/bin/bash
top -b -c -n 1 >topresult
while read line
do
awk '{if( $9 >= 20 ) print $2 ":" $9 ":" $12 }' $line
done <"topresult"
root@magneto [/var/log]

cron :

* * * * * /bin/bash /var/log/resusage.sh 1>>/var/log/server_resusagewq.log

========================
flush log :

root@magneto [/var/log]# cat flush_server_resusage.sh
#!/bin/bash

rm -f /var/log/server_resusage.log
touch /var/log/server_resusage.log
echo "===================`date`===================" >>/var/log/server_resusage.log
root@magneto [/var/log]#

cron :
0 1 * * * /bin/bash /var/log/flush_server_resusage.sh

=========================

try :)
======

No comments:

Post a Comment