Walker News

How To Check Or Monitor Linux Network Traffic Load?

The Linux kernel reports network traffic statistics in proc filesystem, allows system administrator to analyze network traffic load on particular system.

As such, one can develop a shell script and schedule it as a cron job that run every minute, to record network traffic statistic to log file. The log file is in turn being a good source to analyze network traffic trend (e.g. peak and low), network load over an interval (e.g. network load per minute or byte/second), etc.
After network driver loaded and enabled, Linux kernel starts to record total byte receive and transmit to /proc/net/dev. There are few other network statistics in that pseudo file, but those are not interest of this topic now).

For those who are interested, you can download this Linux network traffic recorder shell script for reference.

wNetLoad syntax:
wNetLoad <NIC> <INTERVAL> <OFILE> <DFILE>

where
  • NIC is network interface, e.g. eth0.
  • INTERVAL is number of seconds between 2 records logged to OFILE.
  • OFILE is log file storing rx/tx statistic retrieved from /proc/net/dev.
  • DFILE is log file storing rx/tx in byte-per-second unit derived from the difference of two consecutive records in OFILE.

Note:
  • All options of the script are compulsory
  • OFILE & DFILE:
    • Both log files are written as hidden files in /tmp
    • 1st column: date; 2nd column: RX, 3rd column: TX; 4th column: RX + TX = network load

To test the script:
  1. Upload to Linux system and change it to executable mode, e.g.
    chmod 755 wNetLoad
    
  2. Configure Linux crontab to schedule wNetLoad runs every minutes, e.g.:
    * * * * * /tmp/wNetLoad eth0 60 NLO NLD
    
As the script simply record statistic in /proc/net/dev to files and do some simple calculation to derive network load in unit of byte-per-second, so it should impose very little CPU pressure and should not overload system performance.

To check network load (byte/second), just cat the DFILE (as said, it is a hidden file in /tmp directory, using file name defined by user and .log as file extension).

You can also import it to spreadsheet program (e.g. Microsoft Excel or Calc of OpenOffice.org) and plot a graph to visualize the network traffic trend of Linux system.

Custom Search

2016  •  Privacy Policy