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