The “vmstat” Command in Linux [6 Practical Examples]

The vmstat command in Linux is an essential tool for monitoring and managing the performance of the system. Whether you are a system administrator or a developer, the vmstat command provides valuable information that can help you optimize system performance, identify performance issues, and troubleshoot problems. Moreover, In this article, I will describe all the features and uses of the vmstat command in Linux with multiple examples.

A. Description

The vmstat command in Linux is a powerful tool that provides detailed information about system performance, including memory usage, CPU utilization, and Input/Output (I/O) statistics. This command provides real-time information about various aspects of the system, which makes it a valuable tool for system administrators and developers. With the vmstat command, you can easily identify performance bottlenecks, monitor resource utilization, and troubleshoot various performance-related issues on your Linux system

B. Syntax

The syntax of the vmstat command in Linux is simple, as shown below.

vmstat [OPTION]... [DELAY [COUNT]]

Note: In the syntax above, the OPTION enclosed by the square brackets means it is not mandatory and three dots after the square brackets mean multiple OPTIONS can be used simultaneously after the vmstat command. DELAY refers to the delay between updates in seconds. And the COUNT refers to the number of updates.

C. Options

The vmstat command has multiple options available. Here, I have listed a few of them. However, you can learn more about the vmstat command, its options and their uses by checking the man page.

man vmstat

Useful Options

  • -a, –active: Displays active and inactive memory.
  • -f, –forks: Displays the number of forks since boot.
  • -m, –slabs: Displays slab info.
  • -s, –stats: Displays a table of various event counters and memory statistics.
  • -d, –disk: Displays statistics on disk activities.
  • -D, –disk-sum: Displays statistics on paging activities.
  • -S, –unit character: Displays information in MB or KB.
  • -t, –timestamp: Displays a timestamp with each report.
  • -h, –help: Displays the help page
  • -V, –version: Displays version information.

Note: Commands and their options are case-sensitive in Linux. So, be careful while using them.

Practical Examples of the “vmstat” Command in Linux

In Linux, the vmstat command is a helpful tool to monitor system performance and resource usage. In the section below, I will show you some of the most useful applications for the vmstat command in Linux.

Example 1: Display System Statistics With “vmstat” Command in Linux

You can display the system statistics by simply running the vmstat command in Linux. Here, I will show you the system statistics of my Linux system. You can do the same for your system by following the steps mentioned below.

Steps to Follow >

➊ First, open the Ubuntu Terminal.

 Then, execute the following command.

vmstat

➌ Finally, press the ENTER key.

Output >

In the following image, you can see that I have displayed the system statistics of my system.Showing the system statistics of my system using the vmstat command in linux.

Example 2: Display the Amount of Active and Inactive Memory

Monitoring the memory usage of your system is important to ensure its smooth functioning and avoid performance issues. In Linux, you can display the amount of active and inactive memory using the -a option with the vmstat command. In this article, I will guide you through the process of displaying the amount of active and inactive memory in Linux.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

 Then, execute the following command.

vmstat -a

➌ Then, press the ENTER key.

Output >

In the following image, you can see that I have displayed the amount of active and inactivate memory in kilobytes (kb).The amount of active and inactivate memory has been displayed in kilobytes (kb) using vmstat command in linux.


Similar Readings


Example 3: Display Memory and Scheduling Statistics Using the “vmstat” Command in Linux

Memory and scheduling statistics are key indicators of a computer system‘s performance. These statistics provide information about a system‘s memory usage and task-scheduling capabilities. Here, I will show you the memory and scheduling statistics of my system, which can be achieved by following the mentioned steps.

Steps to Follow >

➊ First, open the Ubuntu Terminal.

 Next, copy the below command in the command prompt.

vmstat -s

➌ Finally, tap the ENTER button.

Output >

You can see in the image below, I have displayed the memory and scheduling status of my system.Showing the memory and scheduling status of my system.

Example 4: Display All Disk Statistics Using the “vmstat” Command in Linux

The vmstat command with the -d option displays disk statistics in Linux. The -d option shows the number of reads and writes, in blocks per second, that have been issued to the disk. You can get the statistics of all disks by following the steps given below.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

 Then, type the following command into the command prompt:

vmstat -d

➌ Now, press the ENTER button.

Output >

In the image below, you can see the statistics of all of my Linux machine’s disks.Showing the statistics of all of my Linux machine’s disks using vmstat command in linux.


Similar Readings


Example 5: Repeatedly Display the Memory Status in Megabytes

To display the memory status in megabytes multiple times, you can use the vmstat command along with the option -S & M and two arguments, i.e., delay and count. So the syntax will be as below.

vmstat -S M delay count

In this example, I’ll show the memory status in megabytes three times over the course of a ten-second period. You can do the same by following the steps below.

Steps to Follow >

➊ At first, Launch the Ubuntu Terminal.

 Then, execute the following command.

vmstat -S M 10 3

➌ Then, press the ENTER key.

Output >

In the following image, you can see that I have displayed the memory status three times in megabyte units.The memory status has been displayed three times in megabyte units.

Example 6: Display Timestamp Information of Each Report

To display timestamp information for each report in the output of the vmstat command in Linux, the -t or –timestamp option can be utilized. This option adds the current date and time to each iteration of the output, providing a clear indication of when the statistics were collected. In this example, I will show you the timestamp information of a report in the output of the vmstat command, which can be achieved by following the steps below.

Steps to Follow >

➊ Open the Ubuntu Terminal.

 Next, run any one of the following commands.

vmstat -t

Alternatively,

vmstat --timestamp

➌ Press the ENTER key.

Output >

The output will show the current status of the system‘s memory, swap, block IO, traps, and CPU activity, along with the date and time of the update.Showing the current status of the system's memory, swap, block IO, traps, and CPU activity, along with the date and time of the update.

Conclusion

The vmstat is a versatile performance monitoring tool in Linux systems. Regardless of your level of experience, vmstat will provide detailed information about your system‘s performance. In addition, vmstat can help you diagnose and resolve performance problems by giving you a detailed picture of various system resources and utilization. By understanding the basics of vmstat, you can take full advantage of this tool, and effectively monitor and manage the performance of your Linux system.


Similar Readings

Rate this post
LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now
S. M. Amdadul Islam

Hello everyone. I am S. M. Amdadul Islam, currently working as a Linux Content Developer Executive at SOFTEKO. I am a Naval Architecture and Marine Engineering (NAME) graduate from the Bangladesh University of Engineering and Technology. In addition to my regular work, I enjoy watching Youtube, discovering new things, gossiping with friends, visiting new places, and taking photos of landscapes. Read Full Bio

Leave a Comment