sar – network statistics (1/2)
sar (System Activity Reporter, from the sysstat package) samples the Linux kernel network counters every interval and shows per-second rates in clean tables. Part 1 covers the -n keywords for interface traffic and errors, NFS, sockets and the IPv4 IP/ICMP/TCP/UDP counters, watched live in a Docker lab.
190.1 Why is it used?
- See per-second traffic, drops and errors per interface (DEV, EDEV).
- Spot TCP retransmits, failed connects and resets (ETCP) when users report timeouts.
- Count sockets and TIME_WAIT (SOCK) on busy servers.
- Keep history: enable the sysstat service and it saves daily sa files you can replay with -f.
- Linux only. Syntax: sar -n KEYWORD interval count (sar -n DEV 1 5 = five samples one second apart).
190.2 How it works
- Step 1
1.n190-client 192.168.210.10 sends iperf3 traffic
- Step 2
2.Traffic crosses the n190-lan bridge to n190-server 192.168.210.20
- Step 3
3.The Docker VM kernel updates its counters for every packet (/proc/net/dev, /proc/net/snmp)
- Step 4
4.sar reads the counters every interval
- Step 5
5.It prints the difference as a per-second rate, plus an Average line
Inside a container sar sees the VM kernel, and only the container's own interfaces (lo, eth0)
- Step 1
1.Client sends a SYN to closed TCP port 9999
- Step 2
2.Server replies RST: connection refused (counts in ETCP atmptf)
- Step 3
3.Client sends a UDP datagram to a closed port
- Step 4
4.Server replies ICMP port unreachable (counts in EICMP idstunr, UDP noport on the receiver)
190.3 -n keywords
| Keyword | Shows | Error keyword |
|---|---|---|
| DEV | Interface traffic | EDEV: interface errors, drops |
| NFS / NFSD | NFS client RPC calls / NFS server RPC and cache | - |
| SOCK / SOCK6 | IPv4 / IPv6 sockets, TIME_WAIT | - |
| IP / IP6 | IPv4 / IPv6 datagrams | EIP / EIP6 |
| ICMP / ICMP6 | ICMP echo, timestamp / neighbor discovery | EICMP / EICMP6 |
| TCP | TCP opens, segments | ETCP: fails, resets, retrans |
| UDP / UDP6 | UDP datagrams, no-port | - |
| FC / SOFT | Fibre Channel HBA frames / softnet processing (part 2) | - |
| ALL | All network keywords | - |
sar -n DEV,EDEV 1 5 # combine with a commasar -n TCP,ETCP,SOCK 2 10sar -n DEV --iface=eth0,eth1 1 5 # only these interfacessar -n DEV -f /var/log/sysstat/sa16 # saved daily data file190.4 Lab setup
uname -r; cat /etc/alpine-releasesar -V 2>&1 | head -1ip -4 addr show eth0$ sar -V 2>&1 | head -1sysstat version 12.6.2$ ip -4 addr show eth0 inet 192.168.210.10/24 brd 192.168.210.255 scope global eth0Kernel 6.18 WSL2. In the outputs below, cols is a small awk helper that keeps only some columns so the table fits.
190.5 DEV and EDEV
# iperf3: client -> server, 5 secondssar -n DEV --iface=eth0 1 3 | cols 1 3 4 6 10$ sar -n DEV --iface=eth0 1 3 | cols 1 3 4 6 1011:17:06 rxpck/s txpck/s txkB/s %ifutil11:17:07 6025.00 9447.00 420326.82 34.4311:17:08 6570.00 10441.00 464929.69 38.0911:17:09 4062.00 6059.00 263622.15 21.60Average: rxpck/s txpck/s txkB/s %ifutilAverage: 5552.33 8649.00 382959.55 31.37- Average about 3 Gbit/s transmit; %ifutil 31% because the veth speed is 10000 Mbit.
- DEV fields: IFACE, rxpck/s, txpck/s, rxkB/s, txkB/s, rxcmp/s, txcmp/s (compressed, mostly 0), rxmcst/s (multicast), %ifutil.
$ sar -n EDEV --iface=eth0 1 3 | cols 1 3 4 6 711:17:14 rxerr/s txerr/s rxdrop/s txdrop/s11:17:15 0.00 0.00 0.00 0.0011:17:16 0.00 0.00 0.00 0.0011:17:17 0.00 0.00 0.00 0.00Average: rxerr/s txerr/s rxdrop/s txdrop/sAverage: 0.00 0.00 0.00 0.00| EDEV field | Meaning |
|---|---|
| rxerr/s / txerr/s | Bad packets received / transmit errors |
| coll/s | Collisions while transmitting |
| rxdrop/s / txdrop/s | Dropped because buffers were full |
| txcarr/s | Carrier errors |
| rxfram/s | Frame alignment errors |
| rxfifo/s / txfifo/s | FIFO overrun errors |
- Healthy link: all zero even under iperf3 load. Growing rxdrop = kernel buffers filling.
- Collisions or carrier errors on modern full-duplex links: check the cable or a duplex mismatch.
190.6 NFS and NFSD
ls /proc/net/rpccat /proc/net/rpc/nfssar -n NFS 1 2 | cols 1 2 3 4 5sar -n NFSD 1 2 | cols 1 2 3 4 5$ sar -n NFS 1 2 | cols 1 2 3 4 511:18:05 call/s retrans/s read/s write/s11:18:06 0.00 0.00 0.00 0.00Average: 0.00 0.00 0.00 0.00$ sar -n NFSD 1 2 | cols 1 2 3 4 511:18:09 scall/s badcall/s packet/s udp/s11:18:10 0.00 0.00 0.00 0.00Average: 0.00 0.00 0.00 0.00- No NFS mount or server in the lab, so /proc/net/rpc/nfs and nfsd do not exist; sysstat 12.6 just shows zeros, no error.
- NFS (client, 6 fields): call/s, retrans/s, read/s, write/s, access/s, getatt/s. Growing retrans = slow server or lossy network.
- NFSD (server, 11 fields): scall/s, badcall/s, packet/s, udp/s, tcp/s, hit/s and miss/s (reply cache), sread/s, swrite/s, saccess/s, sgetatt/s.
190.7 SOCK and SOCK6
$ sar -n SOCK 1 3 | cols 1 2 3 4 711:17:21 totsck tcpsck udpsck tcp-tw11:17:22 5 3 1 611:17:23 5 3 1 611:17:24 5 3 1 6Average: 5 3 1 6- Fields: totsck, tcpsck, udpsck, rawsck, ip-frag, tcp-tw. These are current counts, not per-second rates.
- 6 TIME_WAIT sockets were left over from earlier iperf3 runs; a very high tcp-tw = many short connections.
- SOCK6 (tcp6sck, udp6sck, raw6sck, ip6-frag) was all 0: iperf3 and ping used IPv4. Zero is a real answer.
190.8 IP and EIP
$ sar -n IP,EIP 1 3 | cols 1 2 3 4 511:17:30 irec/s fwddgm/s idel/s orq/s11:17:31 2.00 0.00 2.00 2.0011:17:30 ihdrerr/s iadrerr/s iukwnpr/s idisc/s11:17:31 0.00 0.00 0.00 0.00Average: irec/s fwddgm/s idel/s orq/sAverage: 2.00 0.00 2.00 2.00Average: ihdrerr/s iadrerr/s iukwnpr/s idisc/sAverage: 0.00 0.00 0.00 0.00| IP field | Meaning | EIP field | Meaning |
|---|---|---|---|
| irec/s | Datagrams received (incl. errors) | ihdrerr/s | Header errors: checksum, TTL |
| fwddgm/s | Datagrams forwarded (0: not a router) | iadrerr/s | Invalid destination address |
| idel/s | Delivered to ICMP, TCP, UDP | iukwnpr/s | Unknown protocol |
| orq/s | Sent by local protocols | idisc/s / odisc/s | Input / output discards (no buffer) |
| asmrq/s / asmok/s | Fragments to reassemble / reassembled | onort/s | No route to destination |
| fragok/s / fragcrt/s | Fragmented OK / fragments created | asmf/s / fragf/s | Reassembly failed / cannot fragment (DF set) |
A ping every 0.5 s gives 2 datagrams in and out per second. These counters come from the kernel SNMP MIB (e.g. irec = ipInReceives).
190.9 ICMP, EICMP and a column-shift bug
$ sar -n ICMP,EICMP 1 3 | cols 1 4 5 6 1011:17:36 iech/s iechr/s oech/s otm/s11:17:37 0.00 2.00 0.00 2.0011:17:36 idstunr/s odstunr/s itmex/s isrcq/s11:17:37 2.00 0.00 0.00 0.00Average: iech/s iechr/s oech/s otm/sAverage: 0.00 1.99 0.00 1.99Average: idstunr/s odstunr/s itmex/s isrcq/sAverage: 0.66 0.00 0.00 0.00# kv: /proc/net/snmp group as name valuekv Icmp | sed -n 15,24p$ kv Icmp | sed -n 15,24pOutMsgs 9OutErrors 0OutRateLimitGlobal 0OutRateLimitHost 0OutDestUnreachs 3OutTimeExcds 0OutParmProbs 0OutSrcQuenchs 0OutRedirects 0OutEchos 6- iechr 2 = two echo replies per second; idstunr = ICMP port unreachable for the closed UDP port.
- oech 0 and otm 2 looked wrong: kernel 6.18 added OutRateLimitGlobal and OutRateLimitHost after OutErrors.
- sysstat 12.6 reads columns by position, so OutEchos shifted into otm and odstunr showed 0 though the kernel counted 3 OutDestUnreachs.
- ICMP fields (14): imsg, omsg, iech, iechr, oech, oechr, itm, itmr, otm, otmr, iadrmk, iadrmkr, oadrmk, oadrmkr (i = in, o = out; timestamp/mask are old, almost always 0).
- EICMP fields (12): ierr, oerr, idstunr, odstunr, itmex, otmex (traceroute raises itmex), iparmpb, oparmpb, isrcq, osrcq, iredir, oredir.
190.10 TCP and ETCP
$ sar -n TCP,ETCP 1 3 | cols 1 2 3 4 511:17:41 active/s passive/s iseg/s oseg/s11:17:42 5.00 0.00 5873.00 232884.0011:17:41 atmptf/s estres/s retrans/s isegerr/s11:17:42 3.00 0.00 0.00 0.0011:17:42 active/s passive/s iseg/s oseg/s11:17:43 2.00 0.00 6294.00 312420.0011:17:42 atmptf/s estres/s retrans/s isegerr/s11:17:43 2.00 0.00 1954.00 0.00Average: atmptf/s estres/s retrans/s isegerr/sAverage: 1.67 0.00 651.33 0.00| Field | Meaning |
|---|---|
| active/s | CLOSED -> SYN-SENT (client opens) |
| passive/s | LISTEN -> SYN-RCVD (server opens) |
| iseg/s / oseg/s | Segments received / sent (sent excludes retransmits) |
| atmptf/s | Failed connects |
| estres/s | ESTABLISHED connections reset |
| retrans/s | Retransmitted segments (loss or congestion) |
| isegerr/s | Bad segments (checksum) |
| orsts/s | Segments sent with RST |
5 new connections in the first second, 3 of them to closed port 9999 (atmptf 3); the full-speed iperf3 burst hit 1954 retransmits in one second.
190.11 UDP and ALL
$ sar -n UDP 1 3 | cols 1 2 3 4 511:17:49 idgm/s odgm/s noport/s idgmerr/s11:17:50 0.99 82.18 0.00 0.0011:17:51 0.00 86.00 1.00 0.0011:17:52 0.00 87.00 0.00 0.00Average: 0.33 85.05 0.33 0.00- iperf3 -u -b 1M gives about 86 datagrams/s out; the server's datagram to closed port 9999 shows as noport 1.
- Fields: idgm/s, odgm/s, noport/s (no application on the port), idgmerr/s (other delivery failures, often a full receive buffer on DNS servers).
- sar -n ALL 1 1 prints every keyword in one snapshot, including IPv6 and softnet (covered in part 2).
190.12 Common mistakes
- Trusting every sar number on a newer kernel: the ICMP column shift showed echo requests under otm; keep sysstat updated and cross-check raw counters.
- Reading SOCK values as per-second rates: they are current counts.
- Expecting NFS numbers without NFS in use: you only see zeros.
- Forgetting that inside a container sar shows only that namespace's interfaces.
190.13 Interview tips
- sar vs netstat -s: same kernel counters; netstat shows totals, sar shows per-second rates per interval and can save history.
- Web users get timeouts: check EDEV (drops) and ETCP (retrans, atmptf) first.
- Keywords starting with E show errors (EDEV, EIP, EICMP, ETCP).
- Syntax: sar -n KEYWORD interval count; combine with commas; --iface to filter; -f to read saved files.