TCP重传率计算脚本

用于监控服务器网络状态是否正常.

#!/bin/bash
# tcp_retrans_rate.sh

export PATH='/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin'

read -r s_s s_re < <(netstat -s -t|
    grep -E 'segments send out|segments retransmited'|awk '{print $1}'|xargs)

[[ -f segments_stats ]] || echo 0 0 > segments_stats

read -r s_s_last s_re_last < segments_stats

echo "$s_s" "$s_re" > segments_stats

tcp_re_rate=$(awk 'BEGIN{printf("%.2f",('"$s_re"'-'"$s_re_last"')/('"$s_s"'-'"$s_s_last"')*100)}')

echo "$tcp_re_rate"


exit 0