对TCP的监控可以采用ss.netstat./proc/net/tcp这三个不同的方案来实现.其中ss是最快的 (1)ss命令 [root@manager1 script_py ::]#time ss state all|awk '{++S[$2]} END{for( i in S) {printf "%-11s %s\n",i,S[i]} }' LISTEN ESTAB State TIME-WAIT UNCONN real 0m0.036s user 0m0.024s sys 0m…
#!/bin/bash #this script is used to get tcp and udp connetion status #tcp status metric=$ tmp_file=/tmp/tcp_status.txt /usr/sbin/ss -ant | awk '{++S[$1]};END {for(a in S) print a, S[a]}' > $tmp_file case $metric in closed) output=$(awk '/CLOSED/{prin…