# Cheatsheet & Examples: vmstat

vmstat (Virtual Memory Statistics) provides a real-time view of system performance by reporting statistics about processes, memory, paging, I/O, CPU activity, and other aspects of system performance. It's a useful tool for identifying performance bottlenecks.

## Displaying System Performance Snapshot

Example Usage:
`vmstat 1`

What it does:
Displays a single snapshot of system statistics with a 1-second interval.

Command-line Arguments Explained:

- `1`: The interval in seconds between each update. In this case, it refreshes the output every second.

## Continuously Monitoring System Performance

Example Usage:
`vmstat 5 3`

What it does:
Displays system statistics repeatedly, updating every 5 seconds, and showing 3 updates total.

Command-line Arguments Explained:

- `5`: The interval in seconds between each update.
- `3`: The number of updates to display.  If omitted, vmstat will run indefinitely.

## Displaying Specific Statistics with -a option

Example Usage:
`vmstat -a 5 2`

What it does:
Displays more detailed memory statistics, including active and inactive memory. This can be helpful for understanding memory usage patterns.  It refreshes the output every 5 seconds and shows 2 updates total.

Command-line Arguments Explained:

- `-a`: Displays active and inactive memory statistics.
- `5`: The interval in seconds between each update.
- `2`: The number of updates to display.

## Displaying Disk Statistics

Example Usage:
`vmstat -d 5 2`

What it does:
Displays disk statistics, offering insights into disk I/O performance. It refreshes the output every 5 seconds and shows 2 updates total.

Command-line Arguments Explained:

- `-d`: Displays disk statistics.
- `5`: The interval in seconds between each update.
- `2`: The number of updates to display.

## Displaying Disk Statistics and Processes information

Example Usage:
`vmstat -d -p 5 2`

What it does:
Displays both disk statistics and process information, offering a more comprehensive view of system resource usage, focusing on disk I/O, it refreshes the output every 5 seconds and shows 2 updates total.

Command-line Arguments Explained:

- `-d`: Displays disk statistics.
- `-p`: Displays process information
- `5`: The interval in seconds between each update.
- `2`: The number of updates to display.

## Displaying Memory Statistics and Processes information

Example Usage:
`vmstat -m -p 5 2`

What it does:
Displays both memory statistics and process information, offering a more comprehensive view of system resource usage, focusing on memory and process state, it refreshes the output every 5 seconds and shows 2 updates total.

Command-line Arguments Explained:

- `-m`: Displays memory statistics.
- `-p`: Displays process information
- `5`: The interval in seconds between each update.
- `2`: The number of updates to display.

## Displaying Slabinfo Information

Example Usage:
`vmstat -S 5 2`

What it does:
Displays slabinfo, providing insights into the kernel's memory allocation efficiency.
It refreshes the output every 5 seconds and shows 2 updates total.

Command-line Arguments Explained:

- `-S`: Displays slabinfo statistics.
- `5`: The interval in seconds between each update.
- `2`: The number of updates to display.
