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