7.9. TCP StatisticsThe TCP code maintains a large number of statistics for MIB-II, which is used by SNMP. These counters track details such as the number of established connections and the total number of segments sent, received, and retransmitted. They could be used as an indicator of activity, although you must remember that these statistics usually include loopback traffic. You could also use them when you are troubleshooting networking issues: A large number of retransmissions may be a sign that a network fault is causing packet loss. TCP statistics can be found in the following places:
7.9.1. TCP Statistics InternalsTo explain how the TCP MIB statistics are maintained, we show tcp.c code that updates two of these statistics. static int tcp_snmp_get(queue_t *q, mblk_t *mpctl) { ... tcp = connp->conn_tcp; UPDATE_MIB(&tcp_mib, tcpInSegs, tcp->tcp_ibsegs); tcp->tcp_ibsegs = 0; UPDATE_MIB(&tcp_mib, tcpOutSegs, tcp->tcp_obsegs); tcp->tcp_obsegs = 0; ... See uts/common/inet/tcp/tcp.c UPDATE_MIB increases the statistic by the argument specified. Here the tcpInSegs and tcpOutSegs statistics are updated. These are from standard TCP MIBII statistics that the Solaris 10 SNMP daemon[8] makes available; they are defined on Solaris 10 in the TCP-MIB.txt[9] file.
The tcp.c code also maintains additional MIB statistics. For example, void tcp_rput_data(void *arg, mblk_t *mp, void *arg2) { ... BUMP_MIB(&tcp_mib, tcpInDataInorderSegs); UPDATE_MIB(&tcp_mib, tcpInDataInorderBytes, seg_len); ... See uts/common/inet/tcp/tcp.c BUMP_MIB incremented the tcpInDataInorderSegs statistic by 1, then tcpInDataInorderBytes was updated. These are not standard statistics that are RFC defined, and as such they are not currently made available by the SNMP daemon. They are some of many extra and useful statistics maintained by the Solaris code. A list of these extra statistics is in mib2.h after the comment that reads /* In addition to MIB-II */. typedef struct mib2_tcp { ... /* In addition to MIB-II */ ... /* total # of data segments received in order */ Counter tcpInDataInorderSegs; /* total # of data bytes received in order */ Counter tcpInDataInorderBytes; ... See /usr/include/inet/mib2.h Table 7.2 lists all the extra statistics. The kstat view of TCP statistics (see Section 7.7.2) is copied from these MIB counters during each kstat update.
This behavior leads to an interesting situation: Since kstat provides a copy of all the MIB statistics that Solaris maintains, kstat provides a greater number of statistics than does SNMP. So to delve into TCP statistics in greater detail, use Kstat commands such as kstat and netstat -s. 7.9.2. TCP Statistics from KstatThe kstat command can fetch all the TCP MIB statistics. $ kstat -n tcp module: tcp instance: 0 name: tcp class: mib2 activeOpens 812 attemptFails 312 connTableSize 56 connTableSize6 84 crtime 3.203529053 currEstab 5 estabResets 2 ... You can print all statistics from the TCP module by specifying -m instead of -n; -m, includes tcpstat, a collection of extra kstats that are not contained in the Solaris TCP MIB. And you can print individual statistics by using -s. 7.9.3. TCP Statistics ReferenceTable 7.2 lists all the TCP MIB-II statistics and the Solaris additions. This list was taken from mib2.h. See TCP-MIB.txt for more information about some of these statistics. 7.9.4. TCP Statistics from DTraceDTrace can probe TCP MIB statistics as they are incremented, as the BUMP_MIB and UPDATE_MIB macros were modified to do. The following command lists the TCP MIB statistics from DTrace. # dtrace -ln 'mib:ip::tcp*' ID PROVIDER MODULE FUNCTION NAME 789 mib ip tcp_find_pktinfo tcpInErrs 790 mib ip ip_rput_data_v6 tcpInErrs 791 mib ip ip_tcp_input tcpInErrs 1163 mib ip tcp_ack_timer tcpOutAckDelayed 1164 mib ip tcp_xmit_early_reset tcpOutRsts 1165 mib ip tcp_xmit_ctl tcpOutRsts ... While it can be useful to trace these counters as they are incremented, some needs are still unfulfilled. For example, tracking network activity by PID, UID, project, or zone is not possible with these probes alone: There is no guarantee that they will fire in the context of the responsible thread, so DTrace's variables such as execname and pid sometimes match the wrong process. DTrace can be useful to capture these statistics during an interval of your choice. The following one-liner does this until you press Ctrl-C. # dtrace -n 'mib:::tcp* { @[probename] = sum(arg0); }' dtrace: description 'mib:::tcp* ' matched 93 probes ^C tcpInDataInorderSegs 7 tcpInAckSegs 14 tcpRttUpdate 14 tcpInDataInorderBytes 16 tcpOutDataSegs 16 tcpOutDataBytes 4889 tcpInAckBytes 4934 |