Linux Tutorial
Linux File/Directory Management
Linux Packaging And Compression
Vim Text Editor
Linux Text Processing
Linux Software Installation
Linux User/User Group Management
Linux Permission Management
Linux Filesystem Management
Linux Advanced Filesystem Management
Linux System Management
Linux Backup and Recovery
Linux System Service Management
Linux System Log Management
Linux Boot Management
LAMP/LNMP Environment
SELinux Management
vmstat
, short for virtual memory statistics, is a versatile command-line utility in Linux that provides information about system processes, memory, swap, I/O, and CPU activity. This tutorial will introduce you to the vmstat
command and its usage.
Running vmstat
To run vmstat
, simply type vmstat
in your terminal, followed by an optional interval in seconds:
vmstat [interval]
For example, to display statistics with an interval of 5 seconds, use:
vmstat 5
By default, vmstat
displays a single set of statistics since the last reboot. If an interval is provided, vmstat
will continuously report statistics at the specified interval.
Understanding vmstat output
The output of the vmstat
command consists of several sections:
Procs
r
: The number of runnable processes (running or waiting to run).b
: The number of processes in uninterruptible sleep (waiting for I/O to complete).Memory
swpd
: The amount of virtual memory (swap) used in kilobytes.free
: The amount of idle memory in kilobytes.buff
: The amount of memory used as buffers in kilobytes.cache
: The amount of memory used as cache in kilobytes.Swap
si
: The amount of memory swapped in from disk per second.so
: The amount of memory swapped out to disk per second.I/O
bi
: Blocks received from a block device (blocks input) per second.bo
: Blocks sent to a block device (blocks output) per second.System
in
: The number of interrupts per second, including the clock.cs
: The number of context switches per second.CPU
us
: The percentage of time spent running non-kernel code (user time).sy
: The percentage of time spent running kernel code (system time).id
: The percentage of time spent idle.wa
: The percentage of time spent waiting for I/O.st
: The percentage of time stolen from a virtual machine (only visible in a virtualized environment).Examples of vmstat usage
vmstat
vmstat 2
vmstat -S m
vmstat -d
vmstat -p PARTITION
Replace PARTITION
with the device name of the partition you want to check (e.g., /dev/sda1
).
In conclusion, the vmstat
command is a valuable tool for monitoring system performance and diagnosing issues related to memory, CPU, and I/O utilization. Familiarizing yourself with the vmstat
output and its various options will help you better understand your system's behavior and performance.
How to use the Linux vmstat command:
vmstat
reports information about system processes, memory, paging, block I/O, traps, and CPU activity.# Example: Basic usage of vmstat vmstat
Interpreting output from the vmstat command:
vmstat
output.# Example: Interpret vmstat output man vmstat # Check the manual for detailed information
Monitoring CPU usage with vmstat in Linux:
# Example: Monitor CPU usage with vmstat vmstat 1 # Refresh every 1 second
Viewing memory statistics using vmstat:
# Example: View memory statistics with vmstat vmstat -s
I/O and disk activity analysis with vmstat:
# Example: Analyze I/O and disk activity with vmstat vmstat -d
Network and interrupts monitoring with vmstat:
# Example: Monitor network and interrupts with vmstat vmstat -i
Setting sampling intervals in vmstat on Linux:
# Example: Set sampling intervals with vmstat vmstat 5 # Refresh every 5 seconds
Customizing output format with vmstat:
-n
.# Example: Customize output format with vmstat vmstat -n 1 # Do not display header and refresh every 1 second
Automating system resource monitoring with vmstat:
vmstat
into scripts or monitoring tools for automated resource tracking.# Example: Automate monitoring with vmstat vmstat 1 > output.txt & # Run in the background and save output to a file