The vmstat command displays various statistics about virtual memory, as well as process, CPU, and I/O statistics. By default, the report will provide averages of each statistic since the last system boot, though you can also specify a delay value to sample from a period of time.
Some memory-based statistics include:
- The total virtual memory available.
- The total virtual memory that is free for use.
- The total memory used in buffers and cache.
- The total memory used in swap space.
Some CPU-based statistics include:
- Time spent running user space.
- Time spent running in kernel space.
- Time spent idle.
- Time spent waiting for I/O.
Syntax
The syntax of the vmstat command is:
# vmstat [options] [delay [count]]
Output Delay
It’s recommended to supply vmstat with a delay for a more accurate report. For example, vmstat 5 5 will run the command on a five-second delay for five intervals.
If you encounter the below error while running the vmstat command:
vmstat: command not found
you may try installing the below package as per your choice of distribution:
OS Distribution | Command |
---|---|
Debian | apt-get install procps |
Ubuntu | apt-get install procps |
Alpine | apk add procps |
Arch Linux | pacman -S procps-ng |
Kali Linux | apt-get install procps |
CentOS | yum install procps-ng |
Fedora | dnf install procps-ng |
Raspbian | apt-get install procps |
vmstat Command Examples
1. Display virtual memory statistics:
# vmstat
2. Display reports every 2 seconds for 5 times:
# vmstat 2 5