Useful Commands For Checking IO and Networking-related Issues
Useful Commands For Checking IO and Networking-related Issues
The command:
auditctl -a always,exit -F arch=b64 -S read -k fs_read
is used to configure the Linux Audit subsystem to monitor specific system calls. Hereโs a breakdown of what each part does:
๐ Command Breakdown
-
auditctl: This is the command-line utility to configure the audit system in real time. -
-a always,exit: This tells the audit system to always audit the exit point of a system call. That means it logs the result after the system call has been executed. -
-F arch=b64: This filter specifies the architecture of the system call.b64means 64-bit architecture. On a 64-bit system, you may also want to add a similar rule forb32if you want to catch 32-bit syscalls too. -
-S read: This specifies the system call to monitor. In this case, itโs theread()syscall, which is used to read data from a file descriptor. -
-k fs_read: This assigns a filter key (fs_read) to the rule. This key is useful for searching logs later usingausearch -k fs_read.
โ What It Does
This rule logs every time a 64-bit process calls the read() system call, which is typically used to read from files, sockets, or other file descriptors. Itโs useful for tracking file access or data exfiltration attempts.
๐งช Example Usage
To view logs generated by this rule:
ausearch -k fs_read
This command:
inotifywait -m -r /overlay/mount/point -e open,read,access > /var/log/overlayfs_reads.log &
is using inotifywait to monitor file system activity. Hereโs a detailed breakdown of what itโs doing:
๐ Command Breakdown
-
inotifywait: A command-line utility from theinotify-toolspackage that waits for changes to files using the Linux inotify API. -
-m: Monitor mode โ keeps running and doesnโt exit after the first event. It continuously watches for events. -
-r: Recursive โ watches all subdirectories under/overlay/mount/point. -
/overlay/mount/point: The target directory being monitored. This is likely the mount point of an OverlayFS filesystem. -e open,read,access: Specifies the events to watch for:open: A file was opened.read: A file was read (note: not all versions ofinotifywaitsupportread;accessis more commonly used).access: A file was accessed (read or executed).
-
> /var/log/overlayfs_reads.log: Redirects the output (event logs) to a file for logging purposes. &: Runs the command in the background, allowing the shell to continue accepting other commands.
โ What It Does
This command sets up a background process that continuously monitors the /overlay/mount/point directory and all its subdirectories for any file access, open, or read events. When such an event occurs, it logs the details to:
/var/log/overlayfs_reads.log
This is useful for auditing file access, debugging, or detecting unauthorised reads in environments using OverlayFS (e.g., containers, live systems, or layered filesystems).
The command:
xfs_repair -n /dev/sdX
is used to check the integrity of an XFS filesystem without making any changes. Hereโs a breakdown of what each part does:
๐ Command Breakdown
-
xfs_repair: This is the utility used to repair corrupt or inconsistent XFS filesystems. -
-n: This is the no-modify or dry-run option. It tellsxfs_repairto only check the filesystem and report problems, but not fix them. Itโs useful for safely assessing the health of the filesystem. -
/dev/sdX: This is the block device representing the XFS filesystem you want to check. ReplacesdXwith the actual device name (e.g.,/dev/sda1).
โ What It Does
- Scans the XFS filesystem on
/dev/sdX. - Reports any metadata inconsistencies or corruption.
- Does not modify the filesystem โ itโs safe to run on a mounted filesystem.
โ ๏ธ Important Notes
-
If you want to actually repair the filesystem, you must unmount it first and run:
xfs_repair /dev/sdX -
Running
xfs_repairwithout-non a mounted filesystem can cause data corruption.
Would you like help interpreting the output of xfs_repair -n, or guidance on safely repairing a filesystem?
The command:
iostat -xz 5 > /var/log/iostat.log &
is used to monitor system I/O performance and log it continuously. Hereโs a detailed breakdown:
๐ Command Breakdown
-
iostat: A utility from thesysstatpackage that reports CPU statistics and input/output statistics for devices and partitions. -
-x: Shows extended statistics for each device (e.g., utilisation, queue size, wait time). -
-z: Suppresses output for devices with no activity, making the output cleaner and more focused. -
5: Tellsiostatto repeat the report every 5 seconds. -
> /var/log/iostat.log: Redirects the output to a log file, overwriting it each time the command is restarted. -
&: Runs the command in the background, so your terminal remains usable.
โ What It Does
This command continuously logs detailed I/O statistics every 5 seconds into /var/log/iostat.log. Itโs useful for:
- Diagnosing disk bottlenecks
- Monitoring disk performance over time
- Collecting data for later analysis
๐ Example Output (simplified)
Device: rrqm/s wrqm/s r/s w/s r_await w_await svctm %util
sda 0.00 0.00 1.00 2.00 1.50 2.00 0.50 10.00
This shows read/write rates, wait times, service times, and utilisation for each device.
The command:
blktrace -d /dev/sdX -o - | blkparse -i - > /var/log/blktrace.log &
is used to trace and analyze block I/O operations on a specific device in real time. Hereโs a detailed breakdown:
๐ Command Breakdown
-
blktrace: A tool that captures detailed I/O events from the block layer of the Linux kernel. -
-d /dev/sdX: Specifies the device to trace (replacesdXwith your actual device, e.g.,sda). -
-o -: Directs the output to stdout (standard output) instead of a file. -
| blkparse -i -: Pipes the output ofblktraceintoblkparse, which parses and formats the raw trace data into human-readable form. -
> /var/log/blktrace.log: Redirects the parsed output to a log file. -
&: Runs the entire pipeline in the background.
โ What It Does
This command starts a real-time trace of all block I/O operations on /dev/sdX, parses the trace data, and logs it to /var/log/blktrace.log. It captures events like:
- Queueing
- Merging
- Dispatching
- Completion of I/O requests
This is extremely useful for:
- Performance tuning
- Debugging I/O bottlenecks
- Understanding how the kernel handles disk I/O
๐ Example Use Case
If youโre experiencing high disk latency or want to analyze how a specific workload interacts with the disk subsystem, this tool gives you low-level visibility into those operations.
The command:
journalctl -k -f > /var/log/dmesg_live.log &
is used to continuously monitor and log kernel messages in real time. Hereโs a breakdown of what each part does:
๐ Command Breakdown
-
journalctl: A command-line tool to query and display logs fromsystemd-journald. -
-k: Filters the output to show only kernel messages (equivalent to what youโd see indmesg). -
-f: Follows the log output in real time, similar totail -f. -
> /var/log/dmesg_live.log: Redirects the real-time kernel log output to a file, overwriting it each time the command is restarted. -
&: Runs the command in the background, so your shell remains usable.
โ What It Does
This command starts a background process that:
- Continuously watches for new kernel messages (e.g., hardware events, driver logs, kernel warnings).
- Writes them in real time to
/var/log/dmesg_live.log.
This is useful for:
- Live monitoring of kernel activity
- Debugging hardware or driver issues
- Capturing logs during system events like device hotplugging or kernel panics