1#!/usr/sbin/dtrace -s 2/* 3 * tcpstat.d - print TCP statistics. Uses DTrace. 4 * 5 * This prints TCP statistics every second, retrieved from the MIB provider. 6 * 7 * 15-May-2005, ver 0.70 (first release) 8 * 9 * USAGE: tcpstat.d 10 * 11 * FIELDS: 12 * TCP_out TCP bytes sent 13 * TCP_outRe TCP bytes retransmitted 14 * TCP_in TCP bytes received 15 * TCP_inDup TCP bytes received duplicated 16 * TCP_inUn TCP bytes received out of order 17 * 18 * The above TCP statistics are documented in the mib2_tcp struct 19 * in the /usr/include/inet/mib2.h file; and also in the mib provider 20 * chapter of the DTrace Guide, http://docs.sun.com/db/doc/817-6223. 21 * 22 * COPYRIGHT: Copyright (c) 2005 Brendan Gregg. 23 * 24 * CDDL HEADER START 25 * 26 * The contents of this file are subject to the terms of the 27 * Common Development and Distribution License, Version 1.0 only 28 * (the "License"). You may not use this file except in compliance 29 * with the License. 30 * 31 * You can obtain a copy of the license at Docs/cddl1.txt 32 * or http://www.opensolaris.org/os/licensing. 33 * See the License for the specific language governing permissions 34 * and limitations under the License. 35 * 36 * CDDL HEADER END 37 * 38 * 15-May-2005 Brendan Gregg Created this. 39 */ 40 41#pragma D option quiet 42 43/* 44 * Declare Globals 45 */ 46dtrace:::BEGIN 47{ 48 TCP_out = 0; TCP_outRe = 0; 49 TCP_in = 0; TCP_inDup = 0; TCP_inUn = 0; 50 LINES = 20; line = 0; 51} 52 53/* 54 * Print Header 55 */ 56profile:::tick-1sec { line--; } 57 58profile:::tick-1sec 59/line <= 0 / 60{ 61 printf("%11s %11s %11s %11s %11s\n", 62 "TCP_out", "TCP_outRe", "TCP_in", "TCP_inDup", "TCP_inUn"); 63 64 line = LINES; 65} 66 67/* 68 * Save Data 69 */ 70mib:::tcpOutDataBytes { TCP_out += arg0; } 71mib:::tcpRetransBytes { TCP_outRe += arg0; } 72mib:::tcpInDataInorderBytes { TCP_in += arg0; } 73mib:::tcpInDataDupBytes { TCP_inDup += arg0; } 74mib:::tcpInDataUnorderBytes { TCP_inUn += arg0; } 75 76/* 77 * Print Output 78 */ 79profile:::tick-1sec 80{ 81 printf("%11d %11d %11d %11d %11d\n", 82 TCP_out, TCP_outRe, TCP_in, TCP_inDup, TCP_inUn); 83 84 /* clear values */ 85 TCP_out = 0; 86 TCP_outRe = 0; 87 TCP_in = 0; 88 TCP_inDup = 0; 89 TCP_inUn = 0; 90} 91