1N/A#!/usr/sbin/dtrace -s
1N/A/*
1N/A * udpstat.d - print UDP statistics. Uses DTrace.
1N/A *
1N/A * This prints UDP statistics every second, retrieved from the MIB provider.
1N/A *
1N/A * $Id: udpstat.d 59 2007-10-03 08:21:58Z brendan $
1N/A *
1N/A * USAGE: udpstat.d
1N/A *
1N/A * FIELDS:
1N/A * UDP_out UDP datagrams sent
1N/A * UDP_outErr UDP datagrams errored on send
1N/A * UDP_in UDP datagrams received
1N/A * UDP_inErr UDP datagrams undeliverable
1N/A * UDP_noPort UDP datagrams received to closed ports
1N/A *
1N/A * The above UDP statistics are documented in the mib2_udp 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 * 25-Jul-2005 Brendan Gregg Created this.
1N/A * 25-Jul-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 UDP_in = 0; UDP_out = 0;
1N/A UDP_inErr = 0; UDP_outErr = 0; UDP_noPort = 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 "UDP_out", "UDP_outErr", "UDP_in", "UDP_inErr", "UDP_noPort");
1N/A
1N/A line = LINES;
1N/A}
1N/A
1N/A/*
1N/A * Save Data
1N/A */
1N/Amib:::udp*InDatagrams { UDP_in += arg0; }
1N/Amib:::udp*OutDatagrams { UDP_out += arg0; }
1N/Amib:::udpInErrors { UDP_inErr += arg0; }
1N/Amib:::udpInCksumErrs { UDP_inErr += arg0; }
1N/Amib:::udpOutErrors { UDP_outErr += arg0; }
1N/Amib:::udpNoPorts { UDP_noPort += 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 UDP_out, UDP_outErr, UDP_in, UDP_inErr, UDP_noPort);
1N/A
1N/A /* clear values */
1N/A UDP_out = 0;
1N/A UDP_outErr = 0;
1N/A UDP_in = 0;
1N/A UDP_inErr = 0;
1N/A UDP_noPort = 0;
1N/A}