1N/A#!/usr/sbin/dtrace -s
1N/A/*
1N/A * tcpstat.d - print TCP statistics. Uses DTrace.
1N/A *
1N/A * This prints TCP statistics every second, retrieved from the MIB provider.
1N/A *
1N/A * $Id: tcpstat.d 3 2007-08-01 10:50:08Z brendan $
1N/A *
1N/A * USAGE: tcpstat.d
1N/A *
1N/A * FIELDS:
1N/A * TCP_out TCP bytes sent
1N/A * TCP_outRe TCP bytes retransmitted
1N/A * TCP_in TCP bytes received
1N/A * TCP_inDup TCP bytes received duplicated
1N/A * TCP_inUn TCP bytes received out of order
1N/A *
1N/A * The above TCP statistics are documented in the mib2_tcp struct
1N/A * in the /usr/include/inet/mib2.h file; and also in the mib provider
2N/A * chapter of the DTrace Guide, http://docs.oracle.com/cd/E23824_01/html/E22973.
1N/A *
1N/A * COPYRIGHT: Copyright (c) 2005 Brendan Gregg.
1N/A *
1N/A * CDDL HEADER START
1N/A *
1N/A * The contents of this file are subject to the terms of the
1N/A * Common Development and Distribution License, Version 1.0 only
1N/A * (the "License"). You may not use this file except in compliance
1N/A * with the License.
1N/A *
1N/A * You can obtain a copy of the license at Docs/cddl1.txt
1N/A * or http://www.opensolaris.org/os/licensing.
1N/A * See the License for the specific language governing permissions
1N/A * and limitations under the License.
1N/A *
1N/A * CDDL HEADER END
1N/A *
1N/A * 15-May-2005 Brendan Gregg Created this.
1N/A * 15-May-2005 " " Last update.
1N/A */
1N/A
1N/A#pragma D option quiet
1N/A
1N/A/*
1N/A * Declare Globals
1N/A */
1N/Adtrace:::BEGIN
1N/A{
1N/A TCP_out = 0; TCP_outRe = 0;
1N/A TCP_in = 0; TCP_inDup = 0; TCP_inUn = 0;
1N/A LINES = 20; line = 0;
1N/A}
1N/A
1N/A/*
1N/A * Print Header
1N/A */
1N/Aprofile:::tick-1sec { line--; }
1N/A
1N/Aprofile:::tick-1sec
1N/A/line <= 0 /
1N/A{
1N/A printf("%11s %11s %11s %11s %11s\n",
1N/A "TCP_out", "TCP_outRe", "TCP_in", "TCP_inDup", "TCP_inUn");
1N/A
1N/A line = LINES;
1N/A}
1N/A
1N/A/*
1N/A * Save Data
1N/A */
1N/Amib:::tcpOutDataBytes { TCP_out += arg0; }
1N/Amib:::tcpRetransBytes { TCP_outRe += arg0; }
1N/Amib:::tcpInDataInorderBytes { TCP_in += arg0; }
1N/Amib:::tcpInDataDupBytes { TCP_inDup += arg0; }
1N/Amib:::tcpInDataUnorderBytes { TCP_inUn += arg0; }
1N/A
1N/A/*
1N/A * Print Output
1N/A */
1N/Aprofile:::tick-1sec
1N/A{
1N/A printf("%11d %11d %11d %11d %11d\n",
1N/A TCP_out, TCP_outRe, TCP_in, TCP_inDup, TCP_inUn);
1N/A
1N/A /* clear values */
1N/A TCP_out = 0;
1N/A TCP_outRe = 0;
1N/A TCP_in = 0;
1N/A TCP_inDup = 0;
1N/A TCP_inUn = 0;
1N/A}