]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - cddl/contrib/dtracetoolkit/Net/udpstat.d
Copy head (r256279) to stable/10 as part of the 10.0-RELEASE cycle.
[FreeBSD/stable/10.git] / cddl / contrib / dtracetoolkit / Net / udpstat.d
1 #!/usr/sbin/dtrace -s
2 /*
3  * udpstat.d - print UDP statistics. Uses DTrace.
4  *
5  * This prints UDP statistics every second, retrieved from the MIB provider.
6  *
7  * $Id: udpstat.d 59 2007-10-03 08:21:58Z brendan $
8  *
9  * USAGE:       udpstat.d
10  *
11  * FIELDS:
12  *              UDP_out         UDP datagrams sent
13  *              UDP_outErr      UDP datagrams errored on send
14  *              UDP_in          UDP datagrams received
15  *              UDP_inErr       UDP datagrams undeliverable
16  *              UDP_noPort      UDP datagrams received to closed ports
17  *
18  * The above UDP statistics are documented in the mib2_udp struct
19  * in the /usr/include/inet/mib2.h file; and also in the mib provider
20  * chapter of the DTrace Guide, http://docs.sun.com/db/doc/817-6223.
21  *
22  * COPYRIGHT: Copyright (c) 2005 Brendan Gregg.
23  *
24  * CDDL HEADER START
25  *
26  *  The contents of this file are subject to the terms of the
27  *  Common Development and Distribution License, Version 1.0 only
28  *  (the "License").  You may not use this file except in compliance
29  *  with the License.
30  *
31  *  You can obtain a copy of the license at Docs/cddl1.txt
32  *  or http://www.opensolaris.org/os/licensing.
33  *  See the License for the specific language governing permissions
34  *  and limitations under the License.
35  *
36  * CDDL HEADER END
37  *
38  * 25-Jul-2005  Brendan Gregg   Created this.
39  * 25-Jul-2005     "      "     Last update.
40  */
41
42 #pragma D option quiet
43
44 /*
45  * Declare Globals
46  */
47 dtrace:::BEGIN
48 {
49         UDP_in = 0; UDP_out = 0;
50         UDP_inErr = 0; UDP_outErr = 0; UDP_noPort = 0;
51         LINES = 20; line = 0;
52 }
53
54 /*
55  * Print Header
56  */
57 profile:::tick-1sec { line--; }
58
59 profile:::tick-1sec
60 /line <= 0 /
61 {
62         printf("%11s %11s %11s %11s %11s\n",
63             "UDP_out", "UDP_outErr", "UDP_in", "UDP_inErr", "UDP_noPort");
64
65         line = LINES;
66 }
67
68 /*
69  * Save Data
70  */
71 mib:::udp*InDatagrams   { UDP_in += arg0;       }
72 mib:::udp*OutDatagrams  { UDP_out += arg0;      }
73 mib:::udpInErrors       { UDP_inErr += arg0;    }
74 mib:::udpInCksumErrs    { UDP_inErr += arg0;    }
75 mib:::udpOutErrors      { UDP_outErr += arg0;   }
76 mib:::udpNoPorts        { UDP_noPort += arg0;   }
77
78 /*
79  * Print Output
80  */
81 profile:::tick-1sec
82 {
83         printf("%11d %11d %11d %11d %11d\n",
84             UDP_out, UDP_outErr, UDP_in, UDP_inErr, UDP_noPort);
85
86         /* clear values */
87         UDP_out         = 0;
88         UDP_outErr      = 0;
89         UDP_in          = 0;
90         UDP_inErr       = 0;
91         UDP_noPort      = 0;
92 }