tcplife-bpfcc: Trace the lifespan of TCP sessions and summarize
tcplife-bpfcc [-h] [-T] [-t] [-w] [-s] [-p PID] [-L LOCALPORT] [-D REMOTEPORT] [-4 | -6]
What it does
Trace the lifespan of TCP sessions and summarize. Part of the bcc tools (bpfcc-tools 0.35.0 on Ubuntu, installed as /usr/sbin/tcplife-bpfcc; upstream and other distributions call it tcplife). It loads an eBPF program, so it needs root.
Options you will use
-T, --time- include time column on output (HH:MM:SS)
-t, --timestamp- include timestamp on output (seconds)
-w, --wide- wide column output (fits IPv6 addresses)
-s, --csv- comma separated values output
-p, --pid PID- trace this PID only
-L, --localport LOCALPORT- comma-separated list of local ports to trace.
-D, --remoteport REMOTEPORT- comma-separated list of remote ports to trace.
-4, --ipv4- trace IPv4 family only
-6, --ipv6- trace IPv6 family only
Examples
$ sudo tcplife-bpfcctrace all TCP connect()s
$ sudo tcplife-bpfcc -Tinclude time column (HH:MM:SS)
$ sudo tcplife-bpfcc -wwider columns (fit IPv6)
$ sudo tcplife-bpfcc -stTcsv output, with times & timestamps
$ sudo tcplife-bpfcc -p 181only trace PID 181
$ sudo tcplife-bpfcc -L 80only trace local port 80
$ sudo tcplife-bpfcc -L 80,81only trace local ports 80 and 81
$ sudo tcplife-bpfcc -D 80only trace remote port 80
Gotchas
- Each TCP session when it closes: duration and bytes each way.
- As a normal user it fails with "could not open bpf map: ..., error: Operation not permitted" (unprivileged BPF is off on Ubuntu).
Try tcplife-bpfcc in a real terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.