Ce contenu n'est pas disponible dans la langue sélectionnée.
Chapter 41. Monitoring disk and I/O activity with SystemTap
You can monitor disk and I/O activity with the following scripts.
41.1. Summarizing disk read/write traffic with SystemTap Copier lienLien copié sur presse-papiers!
You can use the disktop.stp SystemTap script to identify which processes are performing the heaviest disk reads and writes to the system.
Prerequisites
- You have installed SystemTap as described in Installing Systemtap.
Procedure
Run the disktop.stp script:
stap --example disktop.stp
# stap --example disktop.stpCopy to Clipboard Copied! Toggle word wrap Toggle overflow The script displays the top ten processes responsible for the heaviest reads or writes to a disk.
The output includes the following data per listed process:
- UID
-
User ID. A user ID of
0refers to the root user. - PID
- The ID of the listed process.
- PPID
- The process ID of the listed process’s parent process.
- CMD
- The name of the listed process.
- DEVICE
- Which storage device the listed process is reading from or writing to.
- T
-
The type of action performed by the listed process, where
Wrefers to write, andRrefers to read. - BYTES
- The amount of data read to or written from disk.
Output of the disktop.stp script looks similar to the following:
41.2. Tracking I/O time for each file read or write with SystemTap Copier lienLien copié sur presse-papiers!
You can use the iotime.stp SystemTap script to monitor the amount of time it takes for each process to read from or write to any file. This helps you to determine what files are slow to load on a system.
Prerequisites
- You have installed SystemTap as described in Installing Systemtap.
Procedure
Run the iotime.stp script:
stap --example iotime.stp
# stap --example iotime.stpCopy to Clipboard Copied! Toggle word wrap Toggle overflow The script tracks each time a system call opens, closes, reads from, and writes to a file. For each file any system call accesses, It counts the number of microseconds it takes for any reads or writes to finish and tracks the amount of data , in bytes, read from or written to the file.
The output contains:
- A timestamp, in microseconds
- Process ID and process name
-
An
accessoriotimeflag The file accessed
If a process was able to read or write any data, a pair of access and
iotimelines should appear together. The access line refers to the time that a given process started accessing a file. The end of the access line will show the amount of data read or written. Theiotimeline will show the amount of time, in microseconds, that the process took in order to perform the read or write.
Output of the iotime.stp script looks similar to the following:
41.3. Tracking cumulative I/O with SystemTap Copier lienLien copié sur presse-papiers!
You can use the traceio.stp SystemTap script to track the cumulative amount of I/O to the system.
Prerequisites
- You have installed SystemTap as described in Installing Systemtap.
Procedure
Run the traceio.stp script:
stap --example traceio.stp
# stap --example traceio.stpCopy to Clipboard Copied! Toggle word wrap Toggle overflow The script prints the top ten executables generating I/O traffic over time. It also tracks the cumulative amount of I/O reads and writes done by those executables. This information is tracked and printed out in 1-second intervals, and in descending order.
Output of the
traceio.stpscript looks similar to the following:
41.4. Monitoring I/O activity on a specific device with SystemTap Copier lienLien copié sur presse-papiers!
You can use the traceio2.stp SystemTap script to monitor I/O activity on a specific device.
Prerequisites
- You have installed SystemTap as described in Installing Systemtap.
Procedure
- Run the traceio2.stp script.
stap --example traceio2.stp 'argument'
# stap --example traceio2.stp 'argument'
This script takes the whole device number as an argument. To find this number you can use:
stat -c "0x%D" directory
# stat -c "0x%D" directory
Where directory is located on the device you want to monitor.
The output contains following:
- The name and ID of any process performing a read or write
-
The function it is performing (
vfs_readorvfs_write) - The kernel device number
Consider following output of # stap traceio2.stp 0x805
41.5. Monitoring reads and writes to a file with SystemTap Copier lienLien copié sur presse-papiers!
You can use the inodewatch.stp SystemTap script to monitor reads from and writes to a file in real time.
Prerequisites
- You have installed SystemTap as described in Installing Systemtap.
Procedure
-
Run the
inodewatch.stpscript.
stap --example inodewatch.stp 'argument1' 'argument2' 'argument3'
# stap --example inodewatch.stp 'argument1' 'argument2' 'argument3'
The script inodewatch.stp takes three command-line arguments:
- The file’s major device number.
- The file’s minor device number.
- The file’s inode number.
You can get these numbers using:
stat -c '%D %i' filename
# stat -c '%D %i' filename
Where filename is an absolute path.
Consider following example:
stat -c '%D %i' /etc/crontab
# stat -c '%D %i' /etc/crontab
The output should look like:
805 1078319
805 1078319
where:
-
805is the base-16 (hexadecimal) device number. The last two digits are the minor device number, and the remaining digits are the major number. -
1078319is the inode number.
To start monitoring /etc/crontab, run:
stap inodewatch.stp 0x8 0x05 1078319
# stap inodewatch.stp 0x8 0x05 1078319
In the first two arguments you must use 0x prefixes for base-16 numbers.
The output contains following:
- The name and ID of any process performing a read or write
-
The function it is performing (
vfs_readorvfs_write) - The kernel device number
The output of this example should look like:
cat(16437) vfs_read 0x800005/1078319 cat(16437) vfs_read 0x800005/1078319
cat(16437) vfs_read 0x800005/1078319
cat(16437) vfs_read 0x800005/1078319