tcplife - Trace TCP sessions and summarize lifespan. Uses Linux eBPF/bcc.
tcplife [-h] [-T] [-t] [-w] [-s] [-p PID] [-D PORTS] [-L PORTS]
This tool traces TCP sessions that open and close while tracing, and prints a
line of output to summarize each one. This includes the IP addresses, ports,
duration, and throughput for the session. This is useful for workload
characterisation and flow accounting: identifying what connections are
happening, with the bytes transferred.
This tool works by using kernel dynamic tracing, and will need to be updated if
the kernel implementation changes. Only TCP state changes are traced, so it is
expected that the overhead of this tool is much lower than typical
Since this uses BPF, only the root user can use this tool.
CONFIG_BPF and bcc.
- Print usage message.
- Comma separated values output (parseable).
- Include a timestamp column (seconds).
- Include a time column (HH:MM:SS).
- Wide column output (fits IPv6 addresses).
- -p PID
- Trace this process ID only (filtered in-kernel).
- -L PORTS
- Comma-separated list of local ports to trace (filtered
- -D PORTS
- Comma-separated list of destination ports to trace
- Trace all TCP sessions, and summarize lifespan and
- # 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
- Time of the call, in HH:MM:SS format.
- Time of the call, in seconds.
- Process ID
- Process name
- IP address family (4 or 6)
- Local IP address.
- Remote IP address.
- Local port.
- Destination port.
- Total transmitted Kbytes.
- Total received Kbytes.
- Lifespan of the session, in milliseconds.
This traces the kernel TCP set state function, which should be called much less
often than send/receive tracing, and therefore have lower overhead. The
overhead of the tool is relative to the rate of new TCP sessions: if this is
high, over 10,000 per second, then there may be noticable overhead just to
print out 10k lines of formatted output per second.
You can find out the rate of new TCP sessions using "sar -n TCP 1",
and adding the active/s and passive/s columns.
As always, test and understand this tools overhead for your types of workloads
before production use.
This is from bcc.
Also look in the bcc distribution for a companion _examples.txt file containing
example usage, output, and commentary for this tool.
Unstable - in development.
tcpaccept(8), tcpconnect(8), tcptop(8)