How to Trace Real-Time TCP Throughput and Active Sockets in Linux Using tcptop

When Linux production servers, container hosts, or database instances experience sudden network spikes, identifying which specific process and socket connection is saturating bandwidth is a critical operational task. Traditional diagnostic tools such as iftop or nload report network interface utilization, but they cannot identify the initiating process ID or application binary name. Conversely, utilities such as ss and netstat display static socket states without showing real-time throughput metrics. Running packet captures with tcpdump captures full packet flows, but analyzing gigabytes of raw PCAP data incurs significant CPU overhead and can quickly exhaust local storage.

The BPF Compiler Collection (BCC) provides an elegant, high-performance solution through the tcptop utility. Powered by extended Berkeley Packet Filters (eBPF), tcptop attaches directly to kernel TCP transmission and reception tracepoints (tcp_sendmsg and tcp_cleanup_rbuf). It summarizes transmission (TX) and reception (RX) throughput in real time, displaying active connections, process IDs, command names, local and remote IP addresses, and port numbers with negligible kernel overhead. This guide covers how to install tcptop, trace high-throughput TCP sockets, filter by process ID, and troubleshoot production network bottlenecks.

Understanding How tcptop Leverages eBPF

Unlike packet capture sniffers that copy raw network packets from kernel space to user space, tcptop operates entirely within the kernel using event-driven eBPF bytecode:

  • Tracepoint Hooking: The tool hooks into the Linux kernel socket buffer management routines—specifically tracing payload bytes passed to tcp_sendmsg() during transmission and bytes processed by tcp_cleanup_rbuf() during reception.
  • In-Kernel Aggregation: Rather than streaming individual packet notifications to user space, eBPF maps aggregate byte counters directly inside kernel memory indexed by connection 4-tuple (source IP, source port, destination IP, destination port) and process identity (PID and command name).
  • Periodic User-Space Sampling: Every designated interval (defaulting to 1 second), tcptop reads the in-kernel hash map, calculates throughput in kilobytes per second (KB/s), prints a top-like interactive dashboard, and clears the counters.
  • Minimal Overhead: Because packets are not copied or parsed beyond standard socket struct headers, tcptop can run safely in high-throughput 10GbE or 40GbE production environments with negligible CPU impact.

Installing tcptop and BCC Tools on Linux

The tcptop utility is packaged as part of the BCC diagnostic suite. On modern Ubuntu and Debian installations, install the required packages using apt:

# Update package repositories and install BCC tools
sudo apt update
sudo apt install bpfcc-tools linux-headers-$(uname -r)

In Debian and Ubuntu, BCC tools are installed with a -bpfcc suffix in /usr/sbin/. You can execute the tool directly as sudo tcptop-bpfcc or add /usr/sbin to your default shell path:

# Verify tcptop installation and review argument flags
sudo tcptop-bpfcc --help

Running Real-Time TCP Throughput Monitoring

To launch real-time monitoring across all system TCP sockets, execute tcptop with root privileges:

# Monitor TCP connection throughput updated every second
sudo tcptop-bpfcc

The console displays a live updating table resembling top, ordered by total bandwidth consumption:

10:14:22 [ Ctrl+C to quit ]
PID    COMM         LADDR                 RADDR                  RX_KB   TX_KB
14820  curl         192.168.1.100:48920   104.21.55.2:443       12450.2    12.4
 3412  postgres     192.168.1.100:5432    192.168.1.150:39210     180.5  8410.8
 1102  sshd         192.168.1.100:22      192.168.1.50:51240        4.2    18.1
  984  node         127.0.0.1:3000        127.0.0.1:42100        120.1   120.1

Key columns include:

  • PID: The process identifier responsible for the network socket.
  • COMM: The command/executable name (e.g., curl, postgres, sshd).
  • LADDR: The local IP address and port number.
  • RADDR: The remote peer IP address and port number.
  • RX_KB: Inbound data received in kilobytes per second during the sampling interval.
  • TX_KB: Outbound data transmitted in kilobytes per second during the sampling interval.

Filtering by Process ID and Display Options

On busy multi-tenant servers hosting hundreds of processes, monitoring all sockets simultaneously can produce excessive screen output. You can narrow the focus using command-line arguments:

Isolating a Specific Process ID

To monitor bandwidth consumption exclusively for a single application—such as a database server or custom API daemon:

# Trace TCP throughput exclusively for PID 3412
sudo tcptop-bpfcc -p 3412

Filtering Out Localhost Loopback Traffic

Internal inter-process communications over 127.0.0.1 (such as local Redis caches or reverse proxy forwards) can clutter throughput diagnostics. Discard loopback sockets to focus on external network activity:

# Suppress 127.0.0.1 loopback connections
sudo tcptop-bpfcc -S

Adjusting Interval and Refresh Count

To print metrics every 5 seconds for a total of 10 intervals (ideal for logging to a file or running automated benchmarks):

# Refresh every 5 seconds for 10 iterations
sudo tcptop-bpfcc 5 10

Tracing Sockets in Non-Interactive Shells and Log Files

Because tcptop clears the screen by default, logging metrics into administrative audit trails requires suppressing screen clears. Use the -C flag:

# Output sequential timestamped snapshots without clearing terminal
sudo tcptop-bpfcc -C 2 5 > /var/log/network_throughput_audit.log

This generates clean, sequential text blocks suitable for automated log parsers or incident post-mortems.

Troubleshooting Common tcptop Execution Errors

When running tcptop, keep these environment requirements in mind:

  • Missing Linux Kernel Headers: If tcptop fails during startup with an error stating that linux/kconfig.h or kernel headers cannot be found, install matching kernel development packages using sudo apt install linux-headers-$(uname -r).
  • Kernel Lockdown Restrictions: If UEFI Secure Boot kernel lockdown is set to [confidentiality], arbitrary eBPF kprobe attachments are blocked by the kernel. Inspect lockdown status using cat /sys/kernel/security/lockdown.
  • IPv6 Socket Tracing: By default, tcptop tracks both IPv4 and IPv6 traffic. If IPv6 sockets do not appear, pass the -6 flag explicitly to isolate IPv6 communication channels.

Using tcptop provides systems engineers and DevOps teams with instant, real-time attribution of network bandwidth consumption, accelerating root-cause analysis and eliminating guesswork during production network saturation events.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.