Linux監控郵件發送配置java
網絡狀態監控mysql
網絡狀態:netstat 各個狀態的總計,詳情;以及重點端口的詳細鏈接狀況(22,25,80,3306,8080),打印客戶端鏈接數最多的ip。sql
郵件報告當前狀態。apache
對於每一個端口的鏈接數,本身能夠設置閾值,加個if判斷就能夠完成報檢的功能。tomcat
在手機上安裝網易的郵件客戶端,就能夠達到實時提醒的效果。服務器
關於mail的配置,見文章:http://blog.csdn.net/rookie_ceo/article/details/46559195網絡
#!/bin/sh
source /etc/profile
IP=`/sbin/ifconfig|sed -n '/inet addr/s/^[^:]*:\([0-9.]\{7,15\}\) .*/\1/p'|grep -v '127.0.0.1'`
warn_pct=1 #75
warn_name=[NET-State]
performance_path=/monitor/performance
mailtmp=/u01/soft/smonitor/mailtmplet/"$warn_name"tmp.mail
infotmp=/u01/soft/smonitor/mailtmplet/"$warn_name"tmp.tmp
maillist=490073687@qq.com,zhou.xiangxing210@163.com
DT=`date +"%Y-%m-%d %H:%M:%S"`
netstat -nap > $infotmp
cat $infotmp|grep '^tcp' > $infotmp.tmp
stat_help="\n-----------------------------Stat Mean-------------------------------"
stat_help="$stat_help""\n LISTEN:Listening for a connection.偵聽來自遠方的TCP端口的鏈接請求"
stat_help="$stat_help""\n\n SYN-SENT:Active; sent SYN. Waiting for a matching connection request after having sent a connection request."
stat_help="$stat_help""\n 再發送鏈接請求後等待匹配的鏈接請求."
stat_help="$stat_help""\n\n SYN-RECEIVED:Sent and received SYN. Waiting for a confirming connection request acknowledgment "
stat_help="$stat_help""\n after having both received and sent connection requests.再收到和發送一個鏈接請求後等待對方對鏈接請求的確認"
stat_help="$stat_help""\n\n ESTABLISHED:Connection established.表明一個打開的鏈接"
stat_help="$stat_help""\n\n FIN-WAIT-1:Closed; sent FIN.等待遠程TCP鏈接中斷請求,或先前的鏈接中斷請求的確認"
stat_help="$stat_help""\n\n FIN-WAIT-2:Closed; FIN is acknowledged; awaiting FIN.從遠程TCP等待鏈接中斷請求"
stat_help="$stat_help""\n\n CLOSE-WAIT:Received FIN; waiting to receive CLOSE.等待從本地用戶發來的鏈接中斷請求"
stat_help="$stat_help""\n\n CLOSING:Closed; exchanged FIN; waiting for FIN.等待遠程TCP對鏈接中斷的確認"
stat_help="$stat_help""\n\n LAST-ACK:Received FIN and CLOSE; waiting for FIN ACK.等待原來的發向遠程TCP的鏈接中斷請求的確認"
stat_help="$stat_help""\n\n TIME-WAIT:In 2 MSL (twice the maximum segment length) quiet wait after close. 等待足夠的時間以確保遠程TCP接收到鏈接中斷請求的確認"
stat_help="$stat_help""\n\n CLOSED:Connection is closed.沒有任何鏈接狀態"
stat_help="$stat_help""\n------------------------------------------------------------"
echo "您好:" >$mailtmp
echo -e " [$DT]服務器:$IP 網絡鏈接信息以下。\n總計:" >>$mailtmp
cat $infotmp.tmp|awk '{print $6}'|sort |uniq -c|sort >>$mailtmp
echo "[$DT]詳細:">>$mailtmp
cat $infotmp.tmp|awk '{print $7" "$6 }'|sort |uniq -c |sort >>$mailtmp
echo "------------------------------------------------------------" >>$mailtmp
#mysql鏈接數 3306
cat $infotmp.tmp|grep 3306 |grep mysqld|grep -v LISTEN > $infotmp.tmp.3306
mysql_conn=`cat $infotmp.tmp.3306|wc -l`
echo "mysql 3306端口鏈接數:$mysql_conn" >>$mailtmp
echo "mysql 3306端口每一個ip鏈接數統計以下:" >>$mailtmp
cat $infotmp.tmp.3306|awk '{print $5}'|awk -F ':' '{print $4}'|sort |uniq -c|sort >>$mailtmp
echo "------------------------------------------------------------">>$mailtmp
#ssh鏈接數 22
cat $infotmp.tmp|grep 22 |grep sshd|grep -v LISTEN > $infotmp.tmp.22
ssh_conn=`cat $infotmp.tmp.22|wc -l`
echo "ssh 22端口鏈接數:$ssh_conn" >>$mailtmp
echo "ssh 22端口每一個ip鏈接數統計以下:" >>$mailtmp
cat $infotmp.tmp.22|awk '{print $5}'|awk -F ':' '{print $1}'|sort |uniq -c|sort >>$mailtmp
echo "------------------------------------------------------------" >>$mailtmp
#httpd鏈接數 80
cat $infotmp.tmp|grep 80 |grep httpd|grep -v LISTEN > $infotmp.tmp.80
httpd_conn=`cat $infotmp.tmp.80|wc -l`
echo "http 80端口鏈接數:$httpd_conn" >>$mailtmp
echo "http 80端口每一個ip鏈接數統計以下:" >>$mailtmp
cat $infotmp.tmp.80|awk '{print $5}'|awk -F ':' '{print $4}'|sort |uniq -c|sort >>$mailtmp
echo "------------------------------------------------------------" >>$mailtmp
#ssh鏈接數 8080
cat $infotmp.tmp|grep 8080 |grep java|grep -v LISTEN > $infotmp.tmp.8080
apache_conn=`cat $infotmp.tmp.8080|wc -l`
echo "tomcat 8080端口鏈接數:$apache_conn" >>$mailtmp
echo "tomcat 8080端口每一個ip鏈接數統計以下:" >>$mailtmp
cat $infotmp.tmp.8080|awk '{print $5}'|awk -F ':' '{print $4}'|sort |uniq -c|sort >>$mailtmp
echo "------------------------------------------------------------" >>$mailtmp
echo -e "$stat_help">>$mailtmp
DT=`date +"%Y-%m-%d %H:%M:%S"`
echo -e "\nBest Wishes! \n------------------------------------ \nCA system Monitor \n$DT" >> $mailtmp
cat $mailtmp
#cat $mailtmp| mailx -s "$warn_name[網絡監測]:服務器:$IP" $maillist