# Cheatsheet & Examples: iostat

iostat is a command-line tool used to monitor system input/output (I/O) statistics, including CPU utilization and disk activity. It provides insights into disk read/write speeds, I/O queue lengths, and device performance.

## Display Overall System I/O Statistics

Example Usage:
`iostat`

What it does:
Shows a summary of CPU and disk I/O statistics for the entire system. The output includes average values over the time since the last boot.

Command-line Arguments Explained:
- None: The command runs with default options, displaying system-wide I/O data.

## Monitor I/O Statistics at Intervals

Example Usage:
`iostat 1 5`

What it does:
Displays I/O statistics at 1-second intervals for 5 iterations, allowing real-time observation of disk and CPU activity.

Command-line Arguments Explained:
- `1`: Interval in seconds between updates.
- `5`: Number of iterations (updates) to display.

## Show Disk I/O Statistics Only

Example Usage:
`iostat -d`

What it does:
Focuses on disk I/O statistics, omitting CPU utilization details.

Command-line Arguments Explained:
- `-d`: Disables CPU statistics and shows only disk-related data.

## Display Extended Disk I/O Statistics

Example Usage:
`iostat -x`

What it does:
Provides detailed disk I/O statistics, such as average request size, I/O wait time, and service time.

Command-line Arguments Explained:
- `-x`: Enables extended statistics for disks, offering more in-depth metrics.

## Monitor Specific Disks or Devices

Example Usage:
`iostat -d sda sdb`

What it does:
Displays I/O statistics for the specified disks (`sda`, `sdb`) instead of all devices.

Command-line Arguments Explained:
- `-d`: Shows disk statistics.
- `sda sdb`: Specifies one or more disk device names (e.g., `sda`, `sdb`).

## Use Custom Units for I/O Metrics

Example Usage:
`iostat -m 2`

What it does:
Displays I/O statistics in megabytes (MB) instead of kilobytes (KB) or bytes, with updates every 2 seconds.

Command-line Arguments Explained:
- `-m`: Display I/O statistics in megabytes (MB) rather than kilobytes (KB).
- `2`: Interval in seconds between updates.

## Include Timestamps in Output

Example Usage:
`iostat -t 1`

What it does:
Displays I/O statistics at 1-second intervals, with timestamps added to each output line.

Command-line Arguments Explained:
- `-t`: Displays timestamps for each I/O statistics update.

## Show Device Names Instead of Major/Minor Numbers

Example Usage:
`iostat -N`

What it does:
Replaces device major/minor numbers with human-readable device names in the output.

Command-line Arguments Explained:
- `-N`: Displays device names (e.g., `/dev/sda`) instead of numerical identifiers.

## Monitor CPU Utilization Only

Example Usage:
`iostat -c`

What it does:
Focuses on CPU utilization statistics, omitting disk I/O details.

Command-line Arguments Explained:
- `-c`: Displays CPU utilization statistics instead of disk I/O data.

## Show Per-Partition Disk I/O Statistics

Example Usage:
`iostat -d -p 1`

What it does:
Reveals I/O statistics for individual disk partitions (e.g., `sda1`, `sda2`) at 1-second intervals.

Command-line Arguments Explained:
- `-d`: Shows disk statistics.
- `-p`: Displays I/O statistics for each partition of the disk.
