1235368Sgnn#!/usr/sbin/dtrace -s 2235368Sgnn/* 3235368Sgnn * tcpstat.d - print TCP statistics. Uses DTrace. 4235368Sgnn * 5235368Sgnn * This prints TCP statistics every second, retrieved from the MIB provider. 6235368Sgnn * 7235368Sgnn * $Id: tcpstat.d 3 2007-08-01 10:50:08Z brendan $ 8235368Sgnn * 9235368Sgnn * USAGE: tcpstat.d 10235368Sgnn * 11235368Sgnn * FIELDS: 12235368Sgnn * TCP_out TCP bytes sent 13235368Sgnn * TCP_outRe TCP bytes retransmitted 14235368Sgnn * TCP_in TCP bytes received 15235368Sgnn * TCP_inDup TCP bytes received duplicated 16235368Sgnn * TCP_inUn TCP bytes received out of order 17235368Sgnn * 18235368Sgnn * The above TCP statistics are documented in the mib2_tcp struct 19235368Sgnn * in the /usr/include/inet/mib2.h file; and also in the mib provider 20235368Sgnn * chapter of the DTrace Guide, http://docs.sun.com/db/doc/817-6223. 21235368Sgnn * 22235368Sgnn * COPYRIGHT: Copyright (c) 2005 Brendan Gregg. 23235368Sgnn * 24235368Sgnn * CDDL HEADER START 25235368Sgnn * 26235368Sgnn * The contents of this file are subject to the terms of the 27235368Sgnn * Common Development and Distribution License, Version 1.0 only 28235368Sgnn * (the "License"). You may not use this file except in compliance 29235368Sgnn * with the License. 30235368Sgnn * 31235368Sgnn * You can obtain a copy of the license at Docs/cddl1.txt 32235368Sgnn * or http://www.opensolaris.org/os/licensing. 33235368Sgnn * See the License for the specific language governing permissions 34235368Sgnn * and limitations under the License. 35235368Sgnn * 36235368Sgnn * CDDL HEADER END 37235368Sgnn * 38235368Sgnn * 15-May-2005 Brendan Gregg Created this. 39235368Sgnn * 15-May-2005 " " Last update. 40235368Sgnn */ 41235368Sgnn 42235368Sgnn#pragma D option quiet 43235368Sgnn 44235368Sgnn/* 45235368Sgnn * Declare Globals 46235368Sgnn */ 47235368Sgnndtrace:::BEGIN 48235368Sgnn{ 49235368Sgnn TCP_out = 0; TCP_outRe = 0; 50235368Sgnn TCP_in = 0; TCP_inDup = 0; TCP_inUn = 0; 51235368Sgnn LINES = 20; line = 0; 52235368Sgnn} 53235368Sgnn 54235368Sgnn/* 55235368Sgnn * Print Header 56235368Sgnn */ 57235368Sgnnprofile:::tick-1sec { line--; } 58235368Sgnn 59235368Sgnnprofile:::tick-1sec 60235368Sgnn/line <= 0 / 61235368Sgnn{ 62235368Sgnn printf("%11s %11s %11s %11s %11s\n", 63235368Sgnn "TCP_out", "TCP_outRe", "TCP_in", "TCP_inDup", "TCP_inUn"); 64235368Sgnn 65235368Sgnn line = LINES; 66235368Sgnn} 67235368Sgnn 68235368Sgnn/* 69235368Sgnn * Save Data 70235368Sgnn */ 71235368Sgnnmib:::tcpOutDataBytes { TCP_out += arg0; } 72235368Sgnnmib:::tcpRetransBytes { TCP_outRe += arg0; } 73235368Sgnnmib:::tcpInDataInorderBytes { TCP_in += arg0; } 74235368Sgnnmib:::tcpInDataDupBytes { TCP_inDup += arg0; } 75235368Sgnnmib:::tcpInDataUnorderBytes { TCP_inUn += arg0; } 76235368Sgnn 77235368Sgnn/* 78235368Sgnn * Print Output 79235368Sgnn */ 80235368Sgnnprofile:::tick-1sec 81235368Sgnn{ 82235368Sgnn printf("%11d %11d %11d %11d %11d\n", 83235368Sgnn TCP_out, TCP_outRe, TCP_in, TCP_inDup, TCP_inUn); 84235368Sgnn 85235368Sgnn /* clear values */ 86235368Sgnn TCP_out = 0; 87235368Sgnn TCP_outRe = 0; 88235368Sgnn TCP_in = 0; 89235368Sgnn TCP_inDup = 0; 90235368Sgnn TCP_inUn = 0; 91235368Sgnn} 92