tcplife(8)
π tcplife(8) π
Okay bestie, this is the manual for tcplife, from the System Manager's Manual π§. It's all about tracing TCP sessions and summarizing their lifespan. It runs on Linux with eBPF/bcc β¨.
β¨ NAME β¨
tcplife is the tool that traces TCP sessions and summarizes their lifespan π¦. It uses Linux eBPF/bcc, so yeah, it's giving kernel-level main character energy π.
π SYNOPSIS π
tcplife [-h] [-T] [-t] [-w] [-s] [-p PID] [-D PORTS] [-L PORTS] [-4 | -6]
πΈ DESCRIPTION πΈ
Okay so this tool watches TCP sessions that open and close while it's running, and prints one line of output for each session π . Each line tells you the IP addresses, ports, duration, and throughput β¨. It's super useful for workload characterisation and flow accounting, aka figuring out which connections are happening and how many bytes moved through them π. Literally iconic.
Lowkey the trick is how it works: it uses the sock:inet_sock_set_state tracepoint if your kernel has it (that was added in Linux 4.16 π₯). For older kernels, it switches over to kernel dynamic tracing instead. It only traces TCP state changes, so the overhead is expected to be way lower than typical send/receive tracing. No cap π«Ά.
π Since this uses BPF, only the root user can run this tool. Sorry bestie, no exceptions π.
π§ REQUIREMENTS π§
You need CONFIG_BPF and bcc β¨.
π OPTIONS π
-hβ Prints the usage message π.-sβ Gives you comma separated values output, which is parseable π.-tβ Adds a timestamp column, in seconds β±οΈ.-Tβ Adds a time column, inHH:MM:SSformat π.-wβ Wide column output, so IPv6 addresses actually fit π.-p PIDβ Only traces this process ID. The filtering happens in-kernel π₯.-L PORTSβ Only traces these local ports. Pass a comma-separated list, and the filtering happens in-kernel π¦.-D PORTSβ Only traces these destination ports. Also comma-separated, also filtered in-kernel π.-4β Traces the IPv4 family only πΈ.-6β Traces the IPv6 family only β.
π EXAMPLES π
Trace all TCP sessions, and summarize lifespan and throughput:
# tcplife
Include a timestamp column, and wide column output:
# tcplife -tw
Trace PID 181 only:
# tcplife -p 181
Trace connections to local ports 80 and 81 only:
# tcplife -L 80,81
Trace connections to remote port 80 only:
# tcplife -D 80
Trace IPv4 family only:
# tcplife -4
Trace IPv6 family only:
# tcplife -6
π«Ά FIELDS π«Ά
TIMEβ The time of the call, inHH:MM:SSformat π.TIME(s)β The time of the call, in seconds β±οΈ.PIDβ The process ID π.COMMβ The process name π .IPβ The IP address family, which is either 4 or 6 π.LADDRβ The local IP address π .RADDRβ The remote IP address π.LPORTβ The local port πͺ.RPORTβ The remote port π―.TX_KBβ The total transmitted Kbytes π€.RX_KBβ The total received Kbytes π₯.MSβ The lifespan of the session, in milliseconds β.
π₯ OVERHEAD π₯
Okay this part is important. The tool traces the kernel TCP set state function, which should get called way less often than send/receive tracing, so the overhead should be lower π. The real overhead depends on the rate of new TCP sessions. If that's high, like over 10,000 per second, there may be noticeable overhead just from printing 10k lines of formatted output every second π.
To find out the rate of new TCP sessions, you can run sar -n TCP 1 and add up the active/s and passive/s columns π.
β οΈ As always, test and understand this tool's overhead for your type of workload before you use it in production. Don't skip this, it's giving "I-learned-the-hard-way" π.
π SOURCE π
This is from bcc β¨. You can find it here:
https://github.com/iovisor/bcc
Also look in the bcc distribution for a companion _examples.txt file. It has example usage, output, and commentary for this tool π.
π¦ OS π¦
Linux π§
π§ͺ STABILITY π§ͺ
Unstable, since it's still in development π§.
π AUTHOR π
Brendan Gregg π.
π SEE ALSO π
tcpaccept(8), tcpconnect(8), tcptop(8) π
Bye bestie, that's the whole page π«Άβ¨. It's from the USER COMMANDS section, dated 2016-10-19, for tcplife(8) π πΈ.
π¦ where this page comes from
- alpine 3.24: bcc-doc 0.36.1-r1 Β· Apache-2.0
- nixpkgs unstable: bcc 0.37.0
- opensuse-leap 16.0: bcc-tools 0.35.0-160000.2.2 Β· Apache-2.0
- opensuse-leap 16.0: bcc-tools 0.35.0-160000.2.2 Β· Apache-2.0
- opensuse-leap 16.0: bcc-tools 0.35.0-160000.2.2 Β· Apache-2.0
- opensuse-leap 16.0: bcc-tools 0.35.0-160000.2.2 Β· Apache-2.0
- π girlified by anthropic/claude-haiku-5.5 on : a language model's rewrite of the original, under its terms