Solaris / Linux: nicstat Command Show Network Interface Card Statistics

by on March 10, 2013 · 12 comments· LAST UPDATED March 13, 2013

in Command Line Hacks, Hardware, Networking

nicstat-welcomeThe nicstat command is top like utility for network interface card (NIC). It displays information and statistics about all your network card such as packets, kilobytes per second, average packet sizes and more. It works under Solaris and Linux operating systems.

In this post, I will explain how to install and use the nicstat command to find out stats about your NICs under Debian / Ubuntu / RHEL / CentOS Linux operating systems.

The old good netstat -i command

The -i option display a table of all network interfaces along with the following information:
# netstat -i
Sample outputs:

Kernel Interface table
Iface       MTU Met    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0       1500   0 199549124      0      0      0 153882468      0      0      0 BMRU
eth1       1500   0 138357627      0    630      0 151312724      0      0      0 BMRU
lo        16436   0        0      0      0      0        0      0      0      0 LRU

However, nicstat provides more information about your nic such as:

  1. Show TCP statistics.
  2. Show UDP statistics.
  3. Reports bytes in & out.
  4. Report packets in & out.
  5. Reports nic utilization.
  6. Reports nic saturation and more.

Step #1: Download and install nicstat

Type the following wget command to download the latest version of nicstat :
# wget http://nchc.dl.sourceforge.net/project/nicstat/nicstat-1.92.tar.gz

Extract tar ball

Use tar command to extract the tar ball called nicstat-1.92.tar.gz, enter:
# tar xvf nicstat-1.92.tar.gz
You will get both source code and binary files:
# cd nicstat-1.92
# ls -la

Sample outputs:

drwxr-xr-x.  2 509833 wheel   4096 Mar 10 07:43 .
dr-xr-x---. 13 root   root    4096 Mar 10 07:43 ..
-rw-r--r--.  1 509833 wheel   4952 Oct 22 13:05 ChangeLog.txt
-rwxr-xr-x.  1 509833 wheel    475 Oct 15 16:49 dladm.sh
-rw-r--r--.  1 509833 wheel   1312 Oct 17 18:47 enicstat
-rw-r--r--.  1 509833 wheel   8902 Oct 17 18:47 LICENSE.txt
-rw-r--r--.  1 509833 wheel   1629 Sep  4  2012 Makefile.Linux
-rw-r--r--.  1 509833 wheel   1596 Oct 17 19:31 Makefile.Solaris
-rw-r--r--.  1 509833 wheel   9423 Oct 22 13:05 nicstat.1
-rw-r--r--.  1 509833 wheel  67376 Oct 22 13:05 nicstat.c
-rwxr-xr-x.  1 509833 wheel  29645 Mar 10 07:46 .nicstat.RedHat_5_i386
-rwxr-xr-x.  1 509833 wheel   4134 Oct 15 20:38 nicstat.sh
-rwxr-xr-x.  1 509833 wheel  69772 Oct 18 19:35 .nicstat.Solaris_10_i386
-rwxr-xr-x.  1 509833 wheel  74920 Oct 18 19:36 .nicstat.Solaris_10_sparc
-rwxr-xr-x.  1 509833 wheel  77700 Oct 18 19:37 .nicstat.Solaris_11_i386
-rwxr-xr-x.  1 509833 wheel  83636 Oct 18 19:39 .nicstat.Solaris_11_sparc
-rwxr-xr-x.  1 509833 wheel 112448 Oct 18 19:49 .nicstat.Solaris_9_i386
-rwxr-xr-x.  1 509833 wheel 127104 Oct 18 19:44 .nicstat.Solaris_9_sparc
-rwx------.  1 509833 wheel  32250 Oct 18 20:02 .nicstat.Ubuntu_8_i386
-rw-r--r--.  1 509833 wheel    834 Oct 22 13:05 README.txt

Step #2: Install required 32-bit package

You need to install the 32 bit glibc package. It contains standard libraries which is used by nicstat command. Only install the following packages if you are using 64-bit version:

A note about Debian Linux 6.0.5 64 bit version

Type the following command to install required 32 bit libc6:
$ sudo apt-get install libc6-i386

A note about Ubuntu Linux 12.04 LTS 64 bit version

Type the following command to install required 32 bit libc6:
$ sudo apt-get install libc6:i386
cd into nicstat directory and type the following command to crate a soft link to Ubuntu_8_i386 binary:
# cd nicstat-1.92
# ln -s .nicstat.Ubuntu_8_i386 .nicstat.Linux_i386

A note about CentOS / RHEL 6.4 64 bit version

Type the following command to install required 32 bit libc6:
# yum install glibc.i686
cd into nicstat directory and type the following command to crate a soft link to .nicstat.RedHat_5_i386 binary:
# cd nicstat-1.92
# ln -s .nicstat.RedHat_5_i386 .nicstat.RedHat_6_i386

How do I use nicstat command?

Simply type the following command:
# ./nicstat.sh
Sample outputs:

Fig.01: nicstat in action

Fig.01: nicstat in action

Pass the -x option to see extended output:
# ./nicstat.sh -x
Sample outputs:

15:39:22      RdKB    WrKB   RdPkt   WrPkt   IErr  OErr  Coll  NoCP Defer  %Util
eth0         349.4   31.98   325.0   250.6   0.00  0.00  0.00  0.00  0.00   3.12
eth1         28.68   169.4   226.3   247.4   0.00  0.00  0.00  0.00  0.00   1.62

Pass the -s option to see extended output:
# ./nicstat.sh -s
Sample outputs:

    Time      Int          rKB/s          wKB/s
15:40:55     eth0        349.372         31.981
15:40:55     eth1         28.686        169.365

To print summary every 1 second, type:
./nicstat.sh 1
To print summary every 2 second 5 times only, type:
./nicstat.sh 2 5
Sample outputs:

Fig.02: nicstat displaying output 5 times only

Fig.02: nicstat displaying output 5 times only

Understanding nicstat output

The fields of nicstat's from the above output display are:

  1. 5:51:22 (HH:MM:SS) : The time corresponding to the end of the sample in 24 hour clock format.
  2. eth0 and eth1 : The interface name.
  3. rKB/s : Kilobytes/second received.
  4. wKB/s : Kilobytes/second written.
  5. rPk/s : Packets/second received.
  6. wPk/s : Packets/second written.
  7. rAvs : Average size of packets received).
  8. wAvs : Average size of packets transmitted.
  9. %Util : Percentage utilization of the interface. For full-duplex interfaces, this is the greater of rKB/s or wKB/s as a percentage of the interface speed. For half-duplex interfaces, rKB/s and wKB/s are summed.
  10. Sat : This the number of errors/second seen for the interface. An indicator the interface may be approaching saturation. This statistic is combined from a number of kernel statistics. It is recommended to use the -x option to see more individual statistics when attempting to diagnose a network issue.

How do I see my TCP nic stats?

Pass the -t option to see the TCP stats:
# ./nicstat.sh -t
Sample outputs:

16:13:44    InKB   OutKB   InSeg  OutSeg Reset  AttF %ReTX InConn OutCon Drops
TCP         0.00    0.00   811.3   592.2  0.01  0.02 0.000   12.6   2.09  0.02

Where,

  1. InKB : Kilobytes/second received.
  2. OutKB : Kilobytes/second transmitted.
  3. InSeg : TCP Segments/second received.
  4. OutSeg : TCP Segments/second transmitted.
  5. Reset : The number of times TCP connections have made a direct transition to the CLOSED state from either the ESTABLISHED state or the CLOSE-WAIT state.
  6. AttF : The number of times that TCP connections have made a direct transition to the CLOSED state from either the SYN-SENT state or the SYN-RCVD state, plus the number of times TCP connections have made a direct transition to the LISTEN state from the SYN-RCVD state.
  7. %ReTX : Percentage of TCP segments retransmitted - that is, the number of TCP segments transmitted containing one or more previously transmitted octets.
  8. InConn : The number of times that TCP connections have made a direct transition to the SYN-RCVD state from the LISTEN state.
  9. OutCon : The number of times that TCP connections have made a direct transition to the SYN-SENT state from the CLOSED state..
  10. Drops : Number of connections dropped from the completed connection queue and incomplete connection queue.

How do I see my UDP nic stats?

Pass the -u option to see the UDP stats:
# ./nicstat.sh -u
Sample outputs:

16:15:11                    InDG   OutDG     InErr  OutErr
UDP                         0.35    0.36      0.00    0.00

Where,

  1. InDG : UDP Datagrams)/second received.
  2. OutDG : UDP Datagrams)/second transmitted.
  3. InErr : Packets received that could not be processed because they contained errors.
  4. OutErr : Packets that were not successfully transmitted because of errors.

Other option

You can combine options
# ./nicstat.sh -x -t -u
OR pass the -a option which is equivalent to -x -t -u:
# ./nicstat.sh -a
Sample outputs:

16:34:10    InKB   OutKB   InSeg  OutSeg Reset  AttF %ReTX InConn OutCon Drops
TCP         0.00    0.00   545.4   448.5  2.71  0.03 0.000   10.9   21.3  0.00
16:34:10                    InDG   OutDG     InErr  OutErr
UDP                         0.01    0.01      0.00    0.00
16:34:10      RdKB    WrKB   RdPkt   WrPkt   IErr  OErr  Coll  NoCP Defer  %Util
eth0         348.9   31.94   324.5   250.3   0.00  0.00  0.00  0.00  0.00   3.12
eth1         28.71   169.2   227.1   248.1   0.00  0.00  0.00  0.00  0.00   1.62

Print statistics for eth0 interfaces, setting speed of "eth0" and "eth1" to 100mbps/full-duplex and 100mbps/full-duplex, respectively:
# ./nicstat.sh -S eth0:100Full,eth1:100Full 5
Print statistics for eth0 interfaces, setting speed of "eth0" and "eth1" to 100mbps/half-duplex and 1000mbps/full-duplex, respectively:
# ./nicstat.sh -S eth0:100h,eth1:1000 5

References:
  1. nicstat blog entry.
  2. Project home page and/or nicstat - the Solaris and Linux Network Monitoring Tool.
  3. nicstat man page
TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

  • James Culbreath

    Anyone else getting nicstat.sh: can not find platform executable ?

  • nixcraft

    Did you run ln -s? If not try:
    bash -x nicstat.sh

    Note down the output and create a softlink to the Linux executable. Use ls -al to list all platform specific executables.

  • James Culbreath

    So it is telling me:
    + ostype=unknown
    + osrel=unknown
    + cputype=unknown

    Full output of bash-x nicstat.sh found here:
    http://pastebin.com/1rMw0FMe

  • James Culbreath

    Could you go into more detail on what you would like me to do?

  • Fet Hung

    Please help me to fix “nicstat.sh: can not find platform executable”.

  • Mike G

    I am running an Ubuntu 12.04-based distro, Bodhi Linux, 64-bit, with the i386 libraries already installed. when I run #mv Makefile.Linux Makefile, and then #make, I get the following output:

    gcc -O3 -m32 nicstat.c -o nicstat
    In file included from /usr/include/stdio.h:28:0,
    from nicstat.c:33:
    /usr/include/features.h:324:26: fatal error: bits/predefs.h: No such file or directory
    compilation terminated.
    make: *** [nicstat] Error 1

    Am I missing something?

  • nixcraft

    Try ln:

    ln -s .nicstat.Ubuntu_8_i386 .nicstat.Linux_i386

    Or directly run any one of the following command:

    ./.nicstat.Ubuntu_8_i386
    ./.nicstat.Linux_i386
    ./.nicstat.RedHat_5_i386

  • nixcraft

    Just use gcc

    gcc nicstat.c -o nicstat
    ./nicstat

  • nope

    >Pass the -x option to see extended output:

    >Pass the -s option to see extended output:

    This doesn’t look right

  • moa

    there is ubuntu ppa for easy install

  • moa
  • mahesh

    On Redhat/Centos/Amazon EC2, be sure to install the glibc-devel as well:

    yum install glibc.i686 glibc-devel.i686

Previous post:

Next post: