Linux – how to get network QoS statistics in linux kernel

linux-kernelnetworkingqos

Is there a way to get the bandwidth, delay, jitter collision, error rate and loss rate of a certain link through the interface on a local machine?

let's say my machine is connected to a network via two interfaces, one wireless and the other ethernet. I want to compare the quality of these two links through these measurements.

Is there any way to get these measurements in the Linux kernel? (v. 3.5.0)

Best Answer

It is hard to give full details, especially not knowing what distribution you are using and how detailed you want the results to be - so I will just list some very basic examples.

If you are looking to get individual stats for each interface, we can break each item down separately (the following assumes root access on a distro like CentOS):

For bandwidth usage - I really like iftop. When you have iftop installed you could run the following command:

iftop -i eth0 -B

The -B option is for Bytes. Once inside iftop I like to press "T" to get a cummulative total.

For error rate you can easily see this in the output of ifconfig in your console. To get a more streamline approach you could run a very crude command like this (assuming something like Centos):

# ifconfig | grep -E "^\w|errors.* " | sed 's/pack.*errors:/Errors:/g' | sed 's/ drop.*//g' | sed 's/HW.*//g'
eth0      Link encap:Ethernet
          RX Errors:0
          TX Errors:0
eth1      Link encap:Ethernet
          RX Errors:3
          TX Errors:1
lo        Link encap:Local Loopback
          RX Errors:0
          TX Errors:0

This will give you the error count for each interface.

For collisions you can still use ifconfig. To get just the collision count, another basic command would be as follows:

# ifconfig | grep -E "^\w|collisions.* " | sed 's/pack.*collisions:/Collisions:/g' | sed 's/ txq.*//g' | sed 's/HW.*//g'
eth0      Link encap:Ethernet
          collisions:0
eth1      Link encap:Ethernet
          collisions:0
lo        Link encap:Local Loopback
          collisions:0

For dropped packets, still using ifconfig, you can run another simple command:

# ifconfig | grep -E "^\w|dropped.* " | sed 's/pack.*dropped:/Dropped:/g' | sed 's/ over.*//g' | sed 's/HW.*//g'
eth0      Link encap:Ethernet
          RX Dropped:0
          TX Dropped:0
eth1      Link encap:Ethernet
          RX Dropped:1
          TX Dropped:0
lo        Link encap:Local Loopback
          RX Dropped:0
          TX Dropped:0

If you are having a lot of bad packets (errors, collisions, or dropped), you could put the previous 3 commands into a bash script and use the watch command to monitor them:

FILE /tmp/netErrors:

#!/bin/sh

ifconfig | grep -E "^\w|errors.* " | sed 's/pack.*errors:/Errors:/g' | sed 's/ drop.*//g' | sed 's/HW.*//g'
echo
ifconfig | grep -E "^\w|collisions.* " | sed 's/pack.*collisions:/Collisions:/g' | sed 's/ txq.*//g' | sed 's/HW.*//g'
echo
ifconfig | grep -E "^\w|dropped.* " | sed 's/pack.*dropped:/Dropped:/g' | sed 's/ over.*//g' | sed 's/HW.*//g'
echo

COMMAND:

watch /tmp/netErrors

For QoS, it really depends on how you are setting it. For Linux, traffic control is common for setting QoS. To see the current QoS with traffic control you can run the following command:

# tc qdisc ls
qdisc pfifo_fast 0: dev eth0 root refcnt 2 bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
qdisc pfifo_fast 0: dev eth1 root refcnt 2 bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
qdisc pfifo_fast 0: dev eth2 root refcnt 2 bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
qdisc pfifo_fast 0: dev tun0 root refcnt 2 bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1

tc - traffic control command qdisc - queuing disciplines ls - list

To get a good break down of traffic control you should check out the following link on traffic control.

Related Question