1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
<?xml version='1.0'?>
<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
]>
<section id="nettopsect">
<title>Network Profiling</title>
<indexterm>
<primary>script examples</primary>
<secondary>network profiling</secondary>
</indexterm>
<indexterm>
<primary>examples of SystemTap scripts</primary>
<secondary>network profiling</secondary>
</indexterm>
<indexterm>
<primary>network profiling</primary>
<secondary>examples of SystemTap scripts</secondary>
</indexterm>
<remark>
WAR STORY: Top network users by PID http://sourceware.org/systemtap/wiki/WSNetTop?highlight=((WarStories))
</remark>
<remark>
probably http://sourceware.org/systemtap/examples/network/nettop.stp
</remark>
<indexterm>
<primary>profiling the network</primary>
<secondary>examples of SystemTap scripts</secondary>
</indexterm>
<indexterm>
<primary>network traffic, monitoring</primary>
<secondary>examples of SystemTap scripts</secondary>
</indexterm>
<para>This section describes how to profile network activity. <xref linkend="nettop"/> provides a glimpse into how much network traffic each process is generating on a machine.</para>
<formalpara id="nettop">
<title>nettop.stp</title>
<para>
<programlisting>
<xi:include parse="text" href="../testsuite/systemtap.examples/network/nettop.stp" xmlns:xi="http://www.w3.org/2001/XInclude" />
</programlisting>
</para>
</formalpara>
<indexterm>
<primary>script examples</primary>
<secondary>if/else conditionals, alternative syntax</secondary>
</indexterm>
<indexterm>
<primary>examples of SystemTap scripts</primary>
<secondary>if/else conditionals, alternative syntax</secondary>
</indexterm>
<indexterm>
<primary>if/else conditionals, alternative syntax</primary>
<secondary>examples of SystemTap scripts</secondary>
</indexterm>
<para>Note that <command>function print_activity()</command> uses the following
expressions:</para>
<screen>
n_xmit ? @sum(ifxmit[pid, dev, exec, uid])/1024 : 0
n_recv ? @sum(ifrecv[pid, dev, exec, uid])/1024 : 0
</screen>
<para>These expressions are if/else conditionals.
The first statement is simply a more concise way of writing the following
psuedo code:</para>
<screen>
if n_recv != 0 then
@sum(ifrecv[pid, dev, exec, uid])/1024
else
0
</screen>
<para><xref linkend="nettop"/> tracks which processes are generating network traffic on the system, and provides the following information about each process:</para>
<itemizedlist>
<listitem><para><computeroutput>PID</computeroutput> — the ID of the listed process.</para></listitem>
<listitem><para><computeroutput>UID</computeroutput> — user ID. A user ID of <computeroutput>0</computeroutput> refers to the root user.</para></listitem>
<listitem><para><computeroutput>DEV</computeroutput> — which ethernet device the process used to send / receive data (e.g. eth0, eth1)</para></listitem>
<listitem><para><computeroutput>XMIT_PK</computeroutput> — number of packets transmitted by the process</para></listitem>
<listitem><para><computeroutput>RECV_PK</computeroutput> — number of packets received by the process</para></listitem>
<listitem><para><computeroutput>XMIT_KB</computeroutput> — amount of data sent by the process, in kilobytes</para></listitem>
<listitem><para><computeroutput>RECV_KB</computeroutput> — amount of data received by the service, in kilobytes</para></listitem>
</itemizedlist>
<para><xref linkend="nettop"/> provides network profile sampling every 5 seconds. You can change this setting by editing <command>probe timer.ms(5000)</command> accordingly. <xref linkend="nettopoutput"/> contains an excerpt of the output from <xref linkend="nettop"/> over a 20-second period:</para>
<example id="nettopoutput">
<title><xref linkend="nettop"/> Sample Output</title>
<screen>
[...]
PID UID DEV XMIT_PK RECV_PK XMIT_KB RECV_KB COMMAND
0 0 eth0 0 5 0 0 swapper
11178 0 eth0 2 0 0 0 synergyc
PID UID DEV XMIT_PK RECV_PK XMIT_KB RECV_KB COMMAND
2886 4 eth0 79 0 5 0 cups-polld
11362 0 eth0 0 61 0 5 firefox
0 0 eth0 3 32 0 3 swapper
2886 4 lo 4 4 0 0 cups-polld
11178 0 eth0 3 0 0 0 synergyc
PID UID DEV XMIT_PK RECV_PK XMIT_KB RECV_KB COMMAND
0 0 eth0 0 6 0 0 swapper
2886 4 lo 2 2 0 0 cups-polld
11178 0 eth0 3 0 0 0 synergyc
3611 0 eth0 0 1 0 0 Xorg
PID UID DEV XMIT_PK RECV_PK XMIT_KB RECV_KB COMMAND
0 0 eth0 3 42 0 2 swapper
11178 0 eth0 43 1 3 0 synergyc
11362 0 eth0 0 7 0 0 firefox
3897 0 eth0 0 1 0 0 multiload-apple
[...]
</screen>
</example>
<!--
global ifxmit, ifrecv, ifdevs, ifpid, execname, user
probe netdev.transmit
{
p = pid()
execname[p] = execname()
user[p] = uid()
ifdevs[p, dev_name] = dev_name
ifxmit[p, dev_name] <<< length
ifpid[p, dev_name] ++
}
probe netdev.receive
{
p = pid()
execname[p] = execname()
user[p] = uid()
ifdevs[p, dev_name] = dev_name
ifrecv[p, dev_name] <<< length
ifpid[p, dev_name] ++
}
function print_activity()
{
printf("%5s %5s %-7s %7s %7s %7s %7s %-15s\n",
"PID", "UID", "DEV", "XMIT_PK", "RECV_PK",
"XMIT_KB", "RECV_KB", "COMMAND")
foreach ([pid, dev] in ifpid-) {
n_xmit = @count(ifxmit[pid, dev])
n_recv = @count(ifrecv[pid, dev])
printf("%5d %5d %-7s %7d %7d %7d %7d %-15s\n",
pid, user[pid], dev, n_xmit, n_recv,
n_xmit ? @sum(ifxmit[pid, dev])/1024 : 0,
n_recv ? @sum(ifrecv[pid, dev])/1024 : 0,
execname[pid])
}
print("\n")
delete execname
delete user
delete ifdevs
delete ifxmit
delete ifrecv
delete ifpid
}
probe timer.ms(5000)
{
print_activity()
}
-->
</section>
|