Below is a few of my commonly used host monitoring scripts, we can change according to their own situation, and hope to give you a little help.
1. Check the host network card traffic
#!/bin/bash#network#mike.xuwhile : ; do time= ' Date +%m ' -"%d" "%k": "%M ' day= ' date +%m"-"%d" rx_before= ' ifconfig eth0|sed -n ' 8 "p|awk ' {print $2} ' |cut -c7-' tx_before= ' ifconfig eth0|sed -n ' 8 "p|awk ' {print $6} ' | cut -c7-' sleep 2 rx_after= ' ifconfig eth0|sed -n "8" p|awk ' {print $2} ' |cut -c7-' tx_after= ' ifconfig eth0|sed -n ' 8 "p|awk ' {print $6} ' |cut -c7-' rx_result=$[(Rx_after-rx_before)/256] tx_ result=$[(Tx_after-tx_before)/256] echo "$time now_in_speed: "$rx _result" Kbps now_out_speed: "$tx _result" Kbps " sleep 2done
2, System condition monitoring
#!/bin/sh#systemstat.sh#mike.xuip=192.168.1.227top -n 2| grep "Cpu" >>./temp/ cpu.txtfree -m | grep "Mem" >> ./temp/mem.txtdf -k | grep "SDA1" >> ./temp/drive_sda1.txt#df -k | grep sda2 >> ./temp/drive_sda2.txtdf -k | grep "/mnt/storage_0" >> ./temp/mnt_ storage_0.txtdf -k | grep "/mnt/storage_pic" >> ./temp/mnt_storage_ Pic.txttime= ' date +%m '. " %d " "%k ":"%M ' connect= ' netstat -na | grep "219.238.148.30:80" | wc -l " echo "$time $connect" >> ./temp/connect_count.txt
3, monitor the disk space of the host, when the use of more than 90% in space by sending mail to send a warning
#!/bin/bash#monitor available disk spacespace= ' DF | Sed-n '/\/$/P ' | Gawk ' {print $} ' | Sed ' s/%//' if [$SPACE-ge]then[email Protected]fi
4. Monitor CPU and Memory usage
#!/bin/bash#script to capture system statisticsoutfile=/home/xu/capstats.csvdate= ' Date +%m/%d/%y ' time= ' date +%k:%m:%s ' timeout= ' uptime ' vmout= ' vmstat 1 2 ' ' USERS= ' echo $TIMEOUT | gawk ' {print $4} ' ' load= ' echo $TIMEOUT | gawk ' { print $9} ' | sed ' s/,//' ' free= ' echo $VMOUT | sed -n '/[0-9] /P ' | sed -n ' 2p ' | gawk ' {print $4} ' ' idle= ' echo $VMOUT | sed -n '/[0-9]/p ' | sed -n ' 2p ' |gawk ' {print $15} ' ' echo ' $DATE, $TIME, $USERS, $LOAD, $FREE, $IDLE " >> $OUTFILE
5, omni-directional monitoring host
#!/bin/bash# check_xu.sh# 0 * * * * /home/check_xu.sh dat= "' date +%y%m%d ' "hour=" ' date +%h ' "dir="/home/oslog/host_${dat}/${hour} "delay=60count=60# whether the responsible directory existif ! test -d ${DIR}then /bin/mkdir -p ${dir}fi# general checkexport term=linux/usr/ Bin/top -b -d ${delay} -n ${count} > ${dir}/top_${dat}.log 2> &1 &# cpu check/usr/bin/sar -u ${delay} ${count} > ${dir}/ cpu_${dat}.log 2>&1 &#/usr/bin/mpstat -p 0 ${delay} ${count} > ${dir}/cpu_0_${dat}.log 2>&1 &#/usr/bin/mpstat -p 1 ${delay} ${count} > ${dir}/cpu_1_${dat}.log 2>&1 &# memory check/usr/ Bin/vmstat ${delay} ${count} > ${dir}/vmstat_${dat}.log 2>&1 &# i/o check/usr/bin/ iostat ${delay} ${count} > ${dir}/iostat_${dat}.log 2>&1 &# Network check/usr/bin/sar -n dev ${delay} ${count} > ${dir}/net_${dat}. log 2>&1 &#/usr/bin/sar -n edev ${delay} ${count} > ${ dir}/net_edev_${dat}.log 2>&1 &
This article is from the It Dick thread blog, so be sure to keep this source http://68686789.blog.51cto.com/10438688/1717612
Linux a few common monitoring scripts