linux下定時監控tcp連接數的方法和步驟


1. 編寫監控腳本 tcp_statistics.sh
echo `date +"%F %H:%M:%S"` "TCP-ALL" `netstat -anotp |awk '/tcp/ {print $6}'|wc -l` >> tcp_count.txt
echo `date +"%F %H:%M:%S"` "TCP-LISTEN" `netstat -anotp|grep "LISTEN" |wc -l` >>tcp_count.txt
echo `date +"%F %H:%M:%S"` "TCP-ESTABLISHED" `netstat -anotp | grep "ESTABLISHED" |wc -l ` >> tcp_count.txt
echo `date +"%F %H:%M:%S"` "TCP_TIME_WAIT" `netstat -anotp |grep "TIME_WAIT" |wc -l  ` >> tcp_count.txt
echo `date +"%F %H:%M:%S"` "TCP_CLOSE_WAIT" `netstat -anotp |grep "CLOSE_WAIT" |wc -l` >> tcp_count.txt

2. 更改文件權限
chmod 777 tcp_statistics.sh

3. 加入定時任務
crontab -e
*/1 * * * * sh /root/tcp_statistics.sh

3. 重啟定時服務
service crond restart


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM