Several ways to view or count network card traffic in Linux

At work, we often need to view the real-time network card traffic of the server. Usually, we will view the real-time network card traffic of the Linux server in these ways.

Table of contents

1. sar

2. /proc/net/dev

3. ifstat

4. iftop

5. nload

6. iptraf-ng

7. nethogs

8. Expansion


1. sar

The sar command is included in the sysstat toolkit, which provides statistics based on network interfaces, and can also view the number and traffic of packets sent and received per second on the device.

 sar -n DEV 1 2

The meaning of the above command is: read the value to the network card (default eth0) once per second, a total of 2 times, and then display:

Detailed tutorial reference blog: ” sar – one of the most comprehensive system performance analysis tools on Linux

2. cat /proc/net/dev

The Linux kernel provides a mechanism for accessing the kernel’s internal data structures and changing kernel settings at runtime through the /proc file system. The proc file system is a pseudo file system that only exists in memory and does not occupy external memory space. It provides an interface for accessing system kernel data in the manner of a file system. Users and applications can get system information through proc, and can change some parameters of the kernel. Since system information, such as processes, changes dynamically, when a user or an application reads a proc file, the proc file system dynamically reads the required information from the system kernel and submits it.

The /proc file system contains many directories, of which /proc/net/dev is a way for users to read or change network adapters and statistics.

Note: Because proc is a pseudo file system and only exists in memory, the start and end time of the data counted here is: system startup to command execution. If the system restarts at this time, the data will be cleared.

Parameter Description:

  • bytes: the total number of bytes of data sent or received by the interface
  • packets: The total number of packets sent or received by the interface
  • errs: The total number of send or receive errors detected by the device driver

The post Linux Several ways to view or count network card traffic first appeared on Lenix Blog .

This article is reprinted from https://blog.p2hp.com/archives/9296
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment