Get TCP statistics and KPIs in Opensolaris and Solaris 10: tcpKPI.d


I’ve created this DTrace script to get network KPIs (Key Performance Indicators).

It will print this information:

 * FIELDS:
 *              DATE            Time, string
 *              OUT             TCP Out Data Bytes
 *              RET             Number of Retransmited Bytes
 *              IN              TCP In Data Bytes
 *              INDUP           TCP In Duplicated Bytes
 *              UNORD           TCP In UnorderBytes
 *              DROP            TCP Dropped Packets
 *              DROPQ0          TCP Dropped Q0 Queue Packets
 *              ATF             TCP Attempt Fails
 *              NOC             NoCanput events

This script is based on tcpstat.d from Brendan Gregg.

The usage is quite simple. Execute as root user:

root@host:# ./tcpKPI.d [interval [samples]]

It will print very useful information when measuring the performance of the network in Solaris/Opensolaris:

  • RET: Retransmissions.
  • INDUP: Input duplicated bytes
  • DROP and DROPQ0: Dropped packets (on a heavy loaded network).
  • ATF: Attempt Fails when starting a new connection.
  • NOC: NoCanPut events when the system is heavily loaded server.

It’s also useful if you only want to know your bandwidth usage:

  • OUT: TCP Out data bytes.
  • IN: TCP In data bytes.

Here it is:

#!/usr/sbin/dtrace -qs
/*
 * tcpKPI.d - realtime network statistics. Uses DTrace.
 *
 * 11-Ago-2009, ver 0.10        (first release)
 *
 * USAGE:       tcpKPI.d [interval [count]]
 *
 *              interval        seconds
 *              count           number of samples
 *
 * FIELDS:
 *              DATE            Time, string
 *              OUT             TCP Out Data Bytes
 *              RET             Number of Retransmited Bytes
 *              IN              TCP In Data Bytes
 *              INDUP           TCP In Duplicated Bytes
 *              UNORD           TCP In UnorderBytes
 *              DROP            TCP Dropped Packets
 *              DROPQ0          TCP Dropped Q0 Queue Packets
 *              ATF             TCP Attempt Fails
 *              NOC             NoCanput events
 *
 * All of the statistics are printed as a value per interval (not per second).
 *
 *
 * COPYRIGHT: Copyright (c) 2009 Sergio Rodriguez de Guzman
 *
 * CDDL HEADER START
 *
 *  The contents of this file are subject to the terms of the
 *  Common Development and Distribution License, Version 1.0 only
 *  (the "License").  You may not use this file except in compliance
 *  with the License.
 *
 *  You can obtain a copy of the license at Docs/cddl1.txt
 *  or http://www.opensolaris.org/os/licensing.
 *  See the License for the specific language governing permissions
 *  and limitations under the License.
 *
 * CDDL HEADER END
 * 15-May-2005  Brendan Gregg                    Original Script.
 * 11-Aug-2009  Sergio Rodriguez de Guzman       Created this.
 */
 
#pragma D option quiet
#pragma D option defaultargs
 
/* Initialise variables */
dtrace:::BEGIN
{
        INTERVAL = $1 ? $1 : 1;
        counts = $2 ? $2 : -1;
        secs = INTERVAL;
        LINES = 20;
        line = 0;
        TCP_out = 0; TCP_outRe = 0;
        TCP_in = 0; TCP_inDup = 0; TCP_inUn = 0;
        TCP_Drop = 0; TCP_DropQ0 = 0; TCP_Atf = 0;
        TCP_NoCan = 0;
        printf("%20s %8s %5s %8s %5s %5s %5s %5s %5s %3s\n",
            "DATE", "OUT", "RET", "IN", "INDUP", "UNORD", "DROP", "DRPQ0", "ATF", "NOC");
}
 
/*
 * Save Data
 */
mib:::tcpOutDataBytes           { TCP_out += arg0;   }
mib:::tcpRetransBytes           { TCP_outRe += arg0; }
mib:::tcpInDataInorderBytes     { TCP_in += arg0;    }
mib:::tcpInDataDupBytes         { TCP_inDup += arg0; }
mib:::tcpInDataUnorderBytes     { TCP_inUn += arg0;  }
mib:::tcpListenDrop             { TCP_Drop += arg0;  }
mib:::tcpListenDropQ0           { TCP_DropQ0 += arg0;}
mib:::tcpAttemptFails           { TCP_Atf += arg0;   }
 
/*
 * Record NoCanPutNext events
 */
 
fbt::canputnext:return
{
        args[1] == 0 ? TCP_NoCan += 1 : 1;
}
 
profile:::tick-1sec
{
        secs--;
        line++;
}
 
/*
 * Print header if needed
 */
profile:::tick-1sec
/ line == LINES /
{
        line = 0;
        printf("%20s %8s %5s %8s %5s %5s %5s %5s %5s %3s\n",
            "DATE", "OUT", "RET", "IN", "INDUP", "UNORD", "DROP", "DROPQ0", "ATF", "NOC");
}
 
/* Print time */
profile:::tick-1sec
/secs == 0/
{ 
 
        printf("%-20Y", walltimestamp);
        printf("%8d %5d %8d %5d %5d %5d %5d %5d %3d\n",
            TCP_out/INTERVAL, TCP_outRe/INTERVAL, TCP_in/INTERVAL, TCP_inDup/INTERVAL, TCP_inUn/INTERVAL,
                TCP_Drop/INTERVAL, TCP_DropQ0/INTERVAL, TCP_Atf/INTERVAL, TCP_NoCan/INTERVAL);
 
        /* clear values */
        TCP_out   = 0;
        TCP_outRe = 0;
        TCP_in    = 0;
        TCP_inDup = 0;
        TCP_inUn  = 0;
        TCP_Drop  = 0;
        TCP_DropQ0= 0;
        TCP_Atf   = 0;
        TCP_NoCan = 0;
 
        secs = INTERVAL;
        counts--;
}
 
/*
 * End
 */
profile:::tick-1sec
/counts == 0/
{
        exit(0);
}

/Sergio

VN:F [1.9.12_1141]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.12_1141]
Rating: 0 (from 0 votes)
Sphere: Related Content

FacebookTwitterGoogle BookmarksLinkedInShare

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

, ,

  1. No comments yet.
(will not be published)