I have a server with about 65k connections in ip_conntrack. How can I optimize munin script that counts various types of connections (default fw_conntrack
script):
cat /proc/net/ip_conntrack | awk '
BEGIN {
STATE["ESTABLISHED"]=STATE["FIN_WAIT"]=STATE["TIME_WAIT"]=0;
TOTAL=ASSURED=NOREPLY=STATE["SYN_SENT"]=STATE["UDP"]=0;
}
/^tcp/ { STATE[$4]++; }
/^udp/ { STATE["UDP"]++; }
/ASSURED/ { ASSURED++; }
{
TOTAL++;
}
END {
print "established.value " STATE["ESTABLISHED"];
print "fin_wait.value " STATE["FIN_WAIT"];
print "time_wait.value " STATE["TIME_WAIT"];
print "syn_sent.value " STATE["SYN_SENT"];
print "udp.value " STATE["UDP"];
print "assured.value " ASSURED;
print "total.value " TOTAL;
}'
Currently it takes about 30 sec to execute.
Replace
cat /proc/net/ip_conntrack
withconntrack -L
. It's more efficient with large number of connections.Example: