Unix How-To: Checking on Collisions


One metric that helps gauge how well your network is holding up to the strain of busy users and applications is the number of packets that slam into other packets, generating what is called a "collision". Let's check out an easy tool for calculating the collision rate for a particular network interface.

To begin this journey into network traffic analysis, we're going to take a look at the output of the netstat -i command that displays stats for the interfaces used for IP traffic. I've straightened up the output below (lined up the columns) to make it make it more readable, but this is the kind of data you would expect to see:

boson$ netstat -i

Name Mtu Net/Dest Address Ipkts Ierrs Opkts Oerrs Collis Queue

lo0 8232 loopback localhost 250528 0 250528 0 0 0

dmfe0 1500 spants spants 136556959 6 173865370 1723663 27690 0

dmfe1 1500 default 0 0 0 0 0 0

This is a Sun system with two network interfaces, only of which is un use (dnfe0) and, of course, the loopback (lo0).

The number of collisions tells us how many packets (ethernet frames) ended up colliding (being put on the network medium at the same time as) other packets, the result being that each of them would have to be recalled and resent by their respective network interfaces shortly afterwards. A high collision rate would indicate that the network is very busy, possibly overloaded. The more collisions you have, the more packets have to be resent, the more traffic you have and so on.

You can try using the expr command to calculate the percent of collisions, but you aren't likely to get an answer that's worth much:

boson$ expr 27690 / 173865370

You can append a bunch of zeroes to your collision count, but you'll have to then figure out where to put the decimal point when you're done. The answer below represents .015% (one and a half times 1/100th of 1%). In other words, very small.

$ expr 2769000000 / 173865370

You can also use grep to grab the two data fields, awk to run the calculation

boson$ netstat -i | grep ^dmfe0 | awk '{print $9 / $7 }'

If you want to turn your commands into a script, you can do something like this to determine which of your network interfaces are operational. Note that we're omitting the loopback in this command.

ifconfig -a | grep -v ^lo | grep UP | awk '{print $1}' | sed 's/://'

A script that runs through all operational interfaces and provides a collision rate might

look like this:


NICS=`ifconfig -a | grep -v ^lo | grep UP | awk '{print $1}' | sed 's/://'`

for if in $NICS
    echo -n "$if "
    netstat -i | grep ^$if | awk '{print $9 / $7 }' 2>/dev/null

Your output would look something like this:

dmfe 0.000159242

The extra caution of sending errors to /dev/null is just in case an interface is active but has seen no traffic. We won't be comitting the high crime of dividing by zero. This is also the reason for the extra echo at the bottom of the script -- to make sure we're not ending without a linefeed.

This article is published as part of the IDG Contributor Network. Want to Join?

Now Read This: IT Resume Makeover: Our top 11 tips
View Comments
You Might Like
Join the discussion
Be the first to comment on this article. Our Commenting Policies