Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 2 down vote accepted

Replace cat /proc/net/ip_conntrack with conntrack -L. It's more efficient with large number of connections.

Example:

root@utemp:~# time conntrack -L | wc -l
conntrack v0.9.14 (conntrack-tools): 16855 flow entries have been shown.
16855

real    0m0.099s
user    0m0.068s
sys     0m0.036s

root@utemp:~# time cat /proc/net/ip_conntrack | wc -l
16634

real    0m0.270s
user    0m0.008s
sys     0m0.264s
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.