Questo contenuto non è disponibile nella lingua selezionata.
Chapter 39. Monitoring network activity with SystemTap
You can use helpful example SystemTap scripts available in the /usr/share/systemtap/testsuite/systemtap.examples/ directory, upon installing the systemtap-testsuite package, to monitor and investigate the network activity of your system.
39.1. Profiling network activity with SystemTap Copia collegamentoCollegamento copiato negli appunti!
You can use the nettop.stp example SystemTap script to profile network activity. The script tracks which processes are generating network traffic on the system, and provides the following information about each process:
- PID
- The ID of the listed process.
- UID
- User ID. A user ID of 0 refers to the root user.
- DEV
- Which ethernet device the process used to send or receive data (for example, eth0, eth1).
- XMIT_PK
- The number of packets transmitted by the process.
- RECV_PK
- The number of packets received by the process.
- XMIT_KB
- The amount of data sent by the process, in kilobytes.
- RECV_KB
- The amount of data received by the service, in kilobytes.
Prerequisites
- You have installed SystemTap as described in Installing SystemTap.
Procedure
Run the
nettop.stpscript:stap --example nettop.stp
# stap --example nettop.stpCopy to Clipboard Copied! Toggle word wrap Toggle overflow The
nettop.stpscript provides network profile sampling every 5 seconds.Output of the
nettop.stpscript looks similar to the following:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
39.2. Tracing functions called in network socket code with SystemTap Copia collegamentoCollegamento copiato negli appunti!
You can use the socket-trace.stp example SystemTap script to trace functions called from the kernel’s net/socket.c file. This helps you identify, in finer detail, how each process interacts with the network at the kernel level.
Prerequisites
- You have installed SystemTap as described in Installing SystemTap.
Procedure
Run the
socket-trace.stpscript:stap --example socket-trace.stp
# stap --example socket-trace.stpCopy to Clipboard Copied! Toggle word wrap Toggle overflow A 3-second excerpt of the output of the
socket-trace.stpscript looks similar to the following:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
39.3. Monitoring network packet drops with SystemTap Copia collegamentoCollegamento copiato negli appunti!
The network stack in Linux can discard packets for various reasons. Some Linux kernels include a tracepoint, kernel.trace("kfree_skb"), which tracks where packets are discarded.
The dropwatch.stp SystemTap script uses kernel.trace("kfree_skb") to trace packet discards; the script summarizes what locations discard packets in every 5-second interval.
Prerequisites
- You have installed SystemTap as described in Installing SystemTap.
Procedure
Run the
dropwatch.stpscript:stap --example dropwatch.stp
# stap --example dropwatch.stpCopy to Clipboard Copied! Toggle word wrap Toggle overflow Running the
dropwatch.stpscript for 15 seconds results in output similar to the following:Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteTo make the location of packet drops more meaningful, see the
/boot/System.map-$(uname -r)file. This file lists the starting addresses for each function, enabling you to map the addresses in the output of thedropwatch.stpscript to a specific function name. Given the following snippet of the/boot/System.map-$(uname -r)file, the address0xffffffff8024cd0fmaps to the functionunix_stream_recvmsgand the address0xffffffff8044b472maps to the functionarp_rcv:Copy to Clipboard Copied! Toggle word wrap Toggle overflow