Cyberithub

26 iostat, vmstat and mpstat command examples to monitor Linux Performance

Table of Contents

Advertisements

In this article, we will look into 26 iostat, vmstat and mpstat command examples to monitor Linux Server Performance. In a Production Environment, Server performance monitoring is done to keep an eye on the optimal resource utilization. Any under performance of resources due to hardware degradation over a period of time or due to some other factor can cause production loss and any over utilization of resources like CPU and memory may cause the Server to crash, so to avoid these use cases it is very important to keep an eye on all the critical resources. Tools like iostat, vmstat and mpstat collectively can perform such tasks with ease.

iostat and mpstat tools are available from sysstat package whereas vmstat utility is available from procps-ng package. Using these tools you can monitor the Linux CPU utilization, Disk utilization, Memory utilization and other devices utilization. You can even generate reports and stats and transfer it to some file. We will look into the usage of all these tools in great detail as we go through.

Advertisements

25 iostat, vmstat and mpstat command examples to monitor Linux Performance

iostat, vmstat and mpstat command examples to monitor Linux Performance

Also Read: Practical Steps to Install iostat and mpstat command on Linux(RHEL/CentOS 7/8)

iostat examples

Example 1: How to Check iostat version

If you want to check the version of iostat then you need to use iostat -Version command as shown below. As you can see from below output, current iostat version is 10.1.5.

Advertisements
[root@localhost ~]# iostat -Version
sysstat version 10.1.5
(C) Sebastien Godard (sysstat <at> orange.fr)

-Version : Print version number then exit.

Example 2: How to Check I/O Performance using iostat 

If you want to check the I/O Performance of your Linux Server devices then you need to use iostat command as shown below.

Advertisements
[root@localhost ~]# iostat
Linux 3.10.0-1160.2.2.el7.x86_64 (localhost.localdomain) 12/07/2020 _x86_64_ (1 CPU)

avg-cpu: %user %nice %system %iowait %steal %idle
         0.14  0.00  0.14     0.01    0.00  99.71

Device: tps  kB_read/s kB_wrtn/s kB_read kB_wrtn
sda     0.76 24.01     1.17      140590   6833
sdb     0.02 0.46      0.00      2688      0
sdc     0.03 0.90      0.00      5284      0
dm-0    0.67 18.39     0.82      107707   4785
dm-1    0.02 0.38      0.00      2204      0

%user:  This shows the percentage of CPU utilization that occurred while executing at the user level (application).

%nice: This shows the percentage of CPU utilization that occurred while executing at the user level with nice priority.

Advertisements

%system: This shows the percentage of CPU utilization that occurred while executing at the system level (kernel).

%iowait: This shows the percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request.

%steal: This shows the percentage of time spent in involuntary wait by the virtual CPU or CPUs while the hypervisor was servicing another virtual processor.

%idle: This shows the percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request.

Example 3: How to Show only CPU stats using iostat

If you only want to check the CPU stats then you can use -c option with iostat command as shown below. It will only show the CPU Utilization report.

[root@localhost ~]# iostat -c
Linux 3.10.0-1160.2.2.el7.x86_64 (localhost.localdomain) 12/07/2020 _x86_64_ (1 CPU)

avg-cpu: %user %nice %system %iowait %steal %idle
         0.04   0.00   0.09    0.00   0.00  99.87

-c : Display the CPU utilization report. More on iostat Man Page.

Example 4: How to Show only Device Stats Using iostat

If you want to show only the device stats then you need to use -d option with iostat command as shown below.

[root@localhost ~]# iostat -d
Linux 3.10.0-1160.2.2.el7.x86_64 (localhost.localdomain) 12/07/2020 _x86_64_ (1 CPU)

Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda 0.28 5.11 0.65 196942 25176
sdb 0.00 0.07 0.00 2688 0
sdc 0.00 0.14 0.00 5284 0
dm-0 0.26 4.26 0.60 163995 23128
dm-1 0.00 0.06 0.00 2204 0

-d : Display the device utilization report. More on iostat Man Page.

Example 5: How to show CPU and Device Stats in Detail

If you want to check extended stats about both CPU and Device stats then you need to use -x option with iostat command as shown below.

[root@localhost ~]# iostat -x
Linux 3.10.0-1160.2.2.el7.x86_64 (localhost.localdomain) 12/07/2020 _x86_64_ (1 CPU)

avg-cpu: %user %nice %system %iowait %steal %idle
          0.04 0.00    0.09    0.00   0.00  99.87

Device: rrqm/s wrqm/s r/s   w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util
sda     0.00   0.01   0.20 0.08 5.10  0.65   40.80    0.00    0.84   0.59    1.46   0.61   0.02
sdb     0.00   0.00   0.00 0.00 0.07  0.00   46.75    0.00    0.37   0.37    0.00   0.32   0.00
sdc     0.00   0.00   0.00 0.00 0.14  0.00   62.16    0.00    0.52   0.52    0.00   0.36   0.00
dm-0    0.00   0.00   0.19 0.07 4.25  0.60   37.38    0.00    0.93   0.58    1.88   0.64   0.02
dm-1    0.00   0.00   0.00 0.00 0.06  0.00   50.09    0.00    0.32   0.32    0.00   0.24   0.00

-x : Display extended statistics. More on iostat Man Page.

Example 6: How to Show Block Device Stats 

If you want to check only Block device stats then you need to use -p option with iostat command as shown below.

[root@localhost ~]# iostat -p
Linux 3.10.0-1160.2.2.el7.x86_64 (localhost.localdomain) 12/07/2020 _x86_64_ (1 CPU)

avg-cpu: %user %nice %system %iowait %steal %idle
          0.04 0.00    0.09    0.00   0.00  99.87

Device: tps  kB_read/s kB_wrtn/s kB_read kB_wrtn
sda     0.28  5.09      0.65      196942  25208
sda1    0.01  0.70      0.05      27071   2048
sda2    0.26  4.35      0.60      168327  23160
sdb     0.00  0.07      0.00       2688    0
sdc     0.00  0.14      0.00       5284    0
sdc1    0.00  0.10      0.00       3728    0
dm-0    0.26  4.24      0.60      163995  23160
dm-1    0.00  0.06      0.00       2204    0

-p : this option displays statistics for block devices and all their partitions that are used by the system.

Example 7: How to Display iostat output in Megabytes per second

If you want to show iostat output in megabytes per second then you need to use -m option with iostat command as shown below.

[root@localhost ~]# iostat -m
Linux 3.10.0-1160.2.2.el7.x86_64 (localhost.localdomain) 12/07/2020 _x86_64_ (1 CPU)

avg-cpu: %user %nice %system %iowait %steal %idle
          0.04 0.00   0.09     0.00   0.00  99.87

Device: tps  MB_read/s MB_wrtn/s MB_read MB_wrtn
sda     0.28  0.00      0.00       192     24
sdb     0.00  0.00      0.00        2      0
sdc     0.00  0.00      0.00        5      0
dm-0    0.26  0.00      0.00       160     22
dm-1    0.00  0.00      0.00        2      0

-m : Display statistics in megabytes per second. More on iostat Man Page.

Example 8: How to Display iostat output in Kilobytes per second

If you want to show iostat output in Kilobytes per second then you need to use -k option with iostat command as shown below.

[root@localhost ~]# iostat -k
Linux 3.10.0-1160.2.2.el7.x86_64 (localhost.localdomain) 12/07/2020 _x86_64_ (1 CPU)

avg-cpu: %user %nice %system %iowait %steal %idle
         0.04  0.00   0.08    0.00    0.00  99.87

Device: tps  kB_read/s kB_wrtn/s kB_read kB_wrtn
sda     0.25  4.41       0.59     196946 26527
sdb     0.00  0.06       0.00      2688    0
sdc     0.00  0.12       0.00      5284    0
dm-0    0.23  3.68       0.55     163999 24479
dm-1    0.00  0.05       0.00      2204

-k : Display statistics in kilobytes per second. More on iostat Man Page.

Example 9: How to Print Time for each of the iostat report displayed

If you want to show time for each of the iostat report generated you need to use -t option with iostat command as shown below.

[root@localhost ~]# iostat -t
Linux 3.10.0-1160.2.2.el7.x86_64 (localhost.localdomain) 12/07/2020 _x86_64_ (1 CPU)

12/07/2020 11:17:59 AM
avg-cpu: %user %nice %system %iowait %steal %idle
         0.04  0.00    0.08    0.00   0.00  99.87

Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda     0.25 4.41      0.59     196946   26527
sdb     0.00 0.06      0.00      2688      0
sdc     0.00 0.12      0.00      5284      0
dm-0    0.23 3.67      0.55     163999   24479
dm-1    0.00 0.05      0.00      2204      0

-t : Print the time for each report displayed.

vmstat examples

Example 10: How to Check vmstat version

If you want to check vmstat command version then you need to use vmstat -Version command as shown below.

[root@localhost ~]# vmstat -Version
vmstat from procps-ng 3.3.10

-Version : Print version number then exit.

Example 11: How to Check Virtual Memory Performance using vmstat

To check virtual memory stats of your Server you can simply run vmstat command as shown below.

[root@localhost ~]# vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free    buff cache  si so bi bo in cs us sy id  wa st
0 0 0    2418596 2116 135896 0  0  23 1  30 71 0  0  100 0  0

Example 12: How to Display number of Forks since Reboot

If you want to check total number of forks since last reboot then you need to use -f option with vmstat command as shown below.

[root@localhost ~]# vmstat -f
9593 forks

-f : this option displays the number of forks since boot. More on vmstat Man Page.

Example 13: How to Display Slabinfo Using vmstat

If you want to display slabinfo then you need to use -m option with vmstat command as shown below.

[root@localhost ~]# vmstat -m
Cache Num Total Size Pages
nf_conntrack_1 36 36 320 12
rpc_inode_cache 24 24 640 12
xfs_dqtrx 0 0 528 15
xfs_dquot 0 0 496 8
xfs_icr 0 0 168 24
xfs_ili 690 690 176 23
xfs_inode 24904 24904 960 8
xfs_efd_item 19 19 424 19
xfs_da_state 8 8 480 8
xfs_btree_cur 18 18 216 18
xfs_log_ticket 22 22 184 22

-m : Displays slabinfo. More on vmstat Man Page.

Example 14: How to Report Only Disk Statistics Using vmstat

If you want to generated report for only Disk statistics then you need to use -d option with vmstat command as shown below.

[root@localhost ~]# vmstat -d
disk- ------------reads------------ ------------writes----------- -----IO------
total merged sectors   ms   total merged sectors  ms    cur sec
sda    7758    31    393901 4551   3570    288   53453 5063 0 7
sdb 115 0 5376 43 0 0 0 0 0 0
sdc 170 0 10568 88 0 0 0 0 0 0
sr0 0 0 0 0 0 0 0 0 0 0
dm-0 7329 0 328006 4230 3052 0 49357 5560 0 6
dm-1 88 0 4408 28 0 0 0 0 0 0

-d : Report disk statistics. More on vmstat Man Page.

Example 15: How to Display Stats about various Event Counters

To check stats about various event counters and memory in tabular form you need to use vmstat -s command as shown below.

[root@localhost ~]# vmstat -s
2865124 K total memory
361332 K used memory
199544 K active memory
96312 K inactive memory
2328824 K free memory
2116 K buffer memory
172852 K swap cache
2097148 K total swap
0 K used swap
2097148 K free swap
2000 non-nice user cpu ticks
14 nice user cpu ticks
3813 system cpu ticks
4605642 idle cpu ticks
180 IO-wait cpu ticks
0 IRQ cpu ticks

-s : Displays a table of various event counters and memory statistics. More on vmstat Man Page.

Example 16: How to Display Summary of Disk Statistics

If you want to display summary of disk statistics you need to use -D option with vmstat command as shown below.

[root@localhost ~]# vmstat -D
6 disks
3 partitions
15460 total reads
31 merged reads
742259 read sectors
8940 milli reading
6731 writes
296 merged writes
103804 written sectors
10771 milli writing
0 inprogress IO
13 milli spent IO

-D : Report some summary statistics about disk activity. More on vmstat Man Page.

Example 17: How to Append timestamp after each Line of vmstat output

To append timestamp after each line of vmstat output you need to use -t option with vmstat command as shown below.

[root@localhost ~]# vmstat -t
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu----- -----timestamp-----
r b swpd free buff cache si so bi bo in cs us sy id wa st EST
0 0 0 2328896 2116 172852 0 0 4 1 16 49 0 0 100 0 0 2020-12-07 11:45:06

-t : Append timestamp to each line. More on vmstat Man Page.

Example 18: How to Show Detailed Statistics about a Partition

If you are looking to show the detailed statistics about a device partition then you need to use -p option with vmstat command as shown below. In this example we are checking stats about /dev/sda1 partition using vmstat -p /dev/sda1 command.

[root@localhost ~]# vmstat -p /dev/sda1
sda1 reads read sectors writes requested writes
258 54143 4 4096

-p : Detailed statistics about partition. More on vmstat Man Page.

Example 19: How to Show Detailed vmstat output

To check detailed virtual memory stats you need to use -w option with vmstat command as shown below.

[root@localhost ~]# vmstat -w
procs -----------------------memory---------------------- ---swap-- -----io---- -system-- --------cpu--------
r b swpd free    buff cache  si so bi bo in cs us sy id  wa st
0 0  0   2328896 2116 172912 0  0  4  1  16 49  0  0 100 0  0

-w : Wide output mode. More on vmstat Man Page.

mpstat examples

Example 20: How to Check mpstat version

To check current version of mpstat command you need to use mpstat -Version as shown below.

[root@localhost ~]# mpstat -Version
sysstat version 10.1.5
(C) Sebastien Godard (sysstat <at> orange.fr)

-Version : Print version number then exit. More on mpstat Man Page.

Example 21: How to Check CPU Stats Using mpstat command

If you want to check all the processor stats then you need to simply run mpstat command as shown below.

[root@localhost ~]# mpstat
Linux 3.10.0-1160.2.2.el7.x86_64 (localhost.localdomain) 12/07/2020 _x86_64_ (1 CPU)

12:39:34 AM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
12:39:34 AM all 0.13 0.00  0.13 0.01    0.00 0.00  0.00   0.00    0.00  99.73

Example 22: How to Display total sum of CPU Stats using mpstat command

If you want to show the sum of interrupt stats then you need to use -I SUM with mpstat command as shown below. Output will show the sum of total number of interrupts received per second by the CPUs.

[root@localhost ~]# mpstat -I SUM
Linux 3.10.0-1160.2.2.el7.x86_64 (localhost.localdomain) 12/07/2020 _x86_64_ (1 CPU)

09:29:53 AM CPU intr/s
09:29:53 AM all 16.72

-I : Report interrupts statistics. More on mpstat Man Page.

Example 23: How to Display Processor Stats of All the CPUs Using mpstat command

If you want to show the processor stats for all the CPUs then you need to use -P ALL option with mpstat command as shown below.

[root@localhost ~]# mpstat -P ALL
Linux 3.10.0-1160.2.2.el7.x86_64 (localhost.localdomain) 12/08/2020 _x86_64_ (1 CPU)

08:23:41 AM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
08:23:41 AM all 0.57 0.00  0.44  0.02   0.00 0.01   0.00   0.00   0.00  98.95
08:23:41 AM 0   0.57 0.00  0.44  0.02   0.00 0.01   0.00   0.00   0.00  98.95

-P : Indicate the processor number for which statistics are to be reported. More on mpstat Man Page.

Example 24: How to Check Detailed Information Using mpstat command

If you want to show detailed CPU stats then you need to use -A option with mpstat command as shown below.

[root@localhost ~]# mpstat -A
Linux 3.10.0-1160.2.2.el7.x86_64 (localhost.localdomain) 12/08/2020 _x86_64_ (1 CPU)

08:25:03 AM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
08:25:03 AM all 0.55 0.00  0.43  0.02   0.00 0.01  0.00    0.00   0.00  98.99
08:25:03 AM 0   0.55 0.00  0.43  0.02   0.00 0.01  0.00    0.00   0.00  98.99

08:25:03 AM CPU intr/s
08:25:03 AM all 71.11
08:25:03 AM 0 65.90

08:25:03 AM CPU 0/s 1/s 8/s 9/s 12/s 14/s 15/s 18/s 19/s 21/s 22/s NMI/s LOC/s SPU/s PMI/s IWI/s RTR/s RES/s CAL/s TLB/s TRM/s THR/s DFR/s MCE/s MCP/s ERR/s MIS/s PIN/s NPI/s PIW/s
08:25:03 AM 0 0.10 0.05 0.00 0.00 0.10 0.00 1.03 4.09 0.92 2.30 0.00 0.00 57.32 0.00 0.00 5.21 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00

08:25:03 AM CPU HI/s TIMER/s NET_TX/s NET_RX/s BLOCK/s BLOCK_IOPOLL/s TASKLET/s SCHED/s HRTIMER/s RCU/s
08:25:03 AM 0 0.00 37.60 0.19 0.92 2.78 0.00 0.06 0.00 0.00 24.35

Example 25: How to Display mpstat output after every n secs

If you want to display certain number of mpstat output after every n secs then you need to use below mpstat command. In this example we are displaying a total of 5 mpstat output refreshed after every 1 sec.

[root@localhost ~]# mpstat 1 5
Linux 3.10.0-1160.2.2.el7.x86_64 (localhost.localdomain) 12/08/2020 _x86_64_ (1 CPU)

08:26:36 AM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
08:26:37 AM all 0.00 0.00  0.00  0.00   0.00  0.00 0.00   0.00    0.00  100.00
08:26:38 AM all 0.00 0.00  0.00  0.00   0.00  0.00 0.00   0.00    0.00  100.00
08:26:39 AM all 0.00 0.00  0.00  0.00   0.00  0.00 0.00   0.00    0.00  100.00
08:26:40 AM all 0.00 0.00  0.00  0.00   0.00  0.00 0.00   0.00    0.00  100.00
08:26:41 AM all 0.00 0.00  1.00  0.00   0.00  0.00 0.00   0.00    0.00   99.00
Average: all 0.00 0.00 0.20 0.00 0.00 0.00 0.00 0.00 0.00 99.80

Example 26: How to Display Stats of a Specific Processor

If you want to display stats of a specific processor instead of showing for all the processor then you need to provide processor number with -P option as shown in below mpstat command output. In this example we are checking the CPU 0 stats by using mpstat -P 0 command.

[root@localhost ~]# mpstat -P 0
Linux 3.10.0-1160.2.2.el7.x86_64 (localhost.localdomain) 12/08/2020 _x86_64_ (1 CPU)

08:31:05 AM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
08:31:05 AM 0   0.47 0.00  0.37  0.02   0.00  0.01  0.00   0.00   0.00  99.13

 

 

 

Popular Recommendations:-

16 Fdisk command examples to Manage Disk Partitions in Linux

How to Convert/Change time to epoch time using date utility on Linux/Unix Server

How to Install jq(JSON Processor) on RHEL/CentOS 7/8 

7 Simple Steps to Install MTR(My Traceroute) on Linux(RHEL/CentOS 7/8)

How to Install Arpwatch tool on RHEL/CentOS 7/8(Simple and Effective Steps)

How to Install and Use i3 Window Manager on Ubuntu 20.04

How to Suppress all the output of a Linux Bash Shell Script

25 Practical and Useful rpm command examples in Linux{cheatsheet}

Leave a Comment