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