Simple traffic analyzer script

When you are working on embedded systems you couldn't have some useful tools to monitor the system resource;

In the following you will find a simple shell script I use when I want to monitor the network traffic on a Linux box.

This is a Spartan script but It does the work. It is also very simple to modify, for example you can add another parameter to select the period between two consecutive checks.




There is a known bug  , but I haven't time to correct it.

When, the value of the transmitted bytes will overcome the maximum value, you should see a negative value for the current bandwidth.



# The NIC

# Compute the current received bytes
rx_byte_count() {
        grep $1 /proc/net/dev | awk '{print $2}'

# Compute the current transmitted bytes
tx_byte_count() {
        grep $1 /proc/net/dev | awk '{print $10}'

old_rx=$(rx_byte_count $interface)
old_tx=$(tx_byte_count $interface)
echo $old_rx
echo $old_tx

while grep $interface /proc/net/dev >/dev/null; do
        curr_rx=$(rx_byte_count $interface)
        curr_tx=$(tx_byte_count $interface)

        echo "$interface Rx=$rx_diff (B/s)  Tx=$tx_diff (B/s)"

        sleep 1



save this file as then run 

chmod +x

last run the monitor issuing the following command

./ <eth device>


You may also like...