| CONNSTAT(8) | Maintenance Commands and Procedures | CONNSTAT(8) |
connstat — report
TCP connection statistics
connstat |
[-eLP]
[-4|-6]
[-T d|u]
[-F filter]
[-i interval]
[-c count]
[-o
field[,field]...] |
The connstat command reports TCP
connection statistics in tabular form. Each row of the table represents the
activity of one connection. The connstat command
adds virtually no overhead to run as it is aggregating statistics that are
always collected in the kernel.
With no arguments, connstat prints a
single report containing all TCP connections, and includes a basic set of
fields representing IP address and port information, as well as connection
state. The -o flag can be used to specify which
fields to display, and other arguments to filter the set of connections
included in the output.
The arguments are as follows:
-4,
--ipv4-6,
--ipv6-c
count,
--count=count-i.-e,
--established-F option.-F
filter,
--filter=filterfield=value[,field=value]...
Fields that can currently be filtered are laddr, lport, raddr, rport, and state. See the Fields section for a description of these fields. The filter matches a connection if all of the filter elements match, and a field must only appears once in the filter.
-i
interval,
--interval=interval-L,
--no-loopback-o
fields,
--output=fields-P,
--parsable-o flag must also be given to specify which fields
to output and their order. Each line of output will consist of
comma-delimited (,) fields, and no header will be emitted. When also using
the -T option, lines indicating the current time
will begin with “= ”. See
Example 4 for an example of how to
process parsable output.-T
d|u,
--timestamp=d|uSpecify u for a printed representation of the internal representation of time (see time(2)). Specify d for standard date format (see date(1)).
The following fields are supported. Field names are case insensitive. Unless otherwise indicated, the values of fields that represent a count (e.g. bytes or segments) are cumulative since the connection was established. Some of these fields refer to data segments, which are segments that contain non-zero amount of data. All sizes are in bytes.
See RFC 793 for a more complete understanding of the TCP protocol and TCP connection states.
The connstat utility exits 0 on success,
or 1 if an error occurs.
-e option allows the user to get a quick glance of
established connections.
$ connstat -e
LADDR LPORT RADDR RPORT STATE
10.43.37.172 51275 172.16.105.4 389 ESTABLISHED
10.43.37.172 22 172.16.98.16 62270 ESTABLISHED
10.43.37.172 1020 172.16.100.162 2049 ESTABLISHED
10.43.37.172 1019 10.43.11.64 2049 ESTABLISHED
10.43.37.172 22 172.16.98.16 61520 ESTABLISHED
10.43.37.172 80 10.43.16.132 59467 ESTABLISHED
-F option is used to filter a specific
connection, -o is used to output specific fields,
and -i to provide the output interval in seconds.
$ connstat -F lport=22,rport=49675,raddr=172.16.168.30 \
-o inbytes,outbytes -i 1
INBYTES OUTBYTES
9589 18101
INBYTES OUTBYTES
9589 18341
INBYTES OUTBYTES
9589 18501
INBYTES OUTBYTES
9589 18661
...
$ connstat -F lport=41934,rport=50001 \ -o outbytes,suna,cwnd,unsent,retransbytes,rtt -T d -i 1 July 7, 2016 11:04:40 AM EDT OUTBYTES SUNA CWND UNSENT RETRANSBYTES RTT 1647048093 47784 47784 3017352 3701844 495 July 7, 2016 11:04:41 AM EDT OUTBYTES SUNA CWND UNSENT RETRANSBYTES RTT 1660720109 41992 41992 1535032 3765556 673 July 7, 2016 11:04:42 AM EDT OUTBYTES SUNA CWND UNSENT RETRANSBYTES RTT 1661875613 26064 26064 4311688 3829268 571 July 7, 2016 11:04:43 AM EDT OUTBYTES SUNA CWND UNSENT RETRANSBYTES RTT 1681478637 41992 41992 437304 3932076 1471 July 7, 2016 11:04:44 AM EDT OUTBYTES SUNA CWND UNSENT RETRANSBYTES RTT 1692028765 44888 44888 1945800 4014612 921 ...
#!/bin/bash
i=0
connstat -P -F lport=41934,rport=50001 -o rttc,rtts -i 1 | \
while IFS=, read rttc[$i] rtts[$i]; do
if [[ $i != 0 ]]; then
let rtt="(${rtts[$i]} - ${rtts[$i - 1]}) / \
(${rttc[$i]} - ${rttc[$i - 1]})"
print "avg rtt = ${rtt}us"
fi
((i++))
done
The output:
... avg rtt = 992us avg rtt = 829us avg rtt = 712us avg rtt = 869us ...
$ connstat -F state=time_wait,lport=80
LADDR LPORT RADDR RPORT STATE
10.43.37.172 80 172.16.168.30 56067 TIME_WAIT
10.43.37.172 80 172.16.168.30 56068 TIME_WAIT
10.43.37.172 80 172.16.168.30 56070 TIME_WAIT
The command line options for this command are stable, but the
output format when not using the -P option and
diagnostic messages are not.
J. Postel, Transmission Control Protocol, STD 7, RFC 793, September 1981.
V. Paxson, M. Allman, J. Chu, and M. Sargent, Computing TCP's Retransmission Timer, RFC 6298, June 2011.
| March 10, 2023 | OmniOS |