Home  >  Article  >  System Tutorial  >  Introduction to commands for Linux performance monitoring

Introduction to commands for Linux performance monitoring

WBOY
WBOYforward
2023-12-29 19:43:271108browse
Introduction This is part of our ongoing series on Linux commands and performance monitoring. Both vmstat and iostat commands are available on all major unix-like systems

If the vmstat and iostat commands are not available on your system, please install the sysstat package. The vmstat, sar and iostat commands are all included in the sysstat (system monitoring tool) package. The iostat command generates statistics for the CPU and all devices. You can download the source code package from (http://sebastien.godard.pagesperso-orange.fr/download.html) to compile and install sysstat, but we recommend installing it through the YUM command.

Introduction to commands for Linux performance monitoring

Install sysstat in Linux system
#yum -y install sysstat

vmstat - Brief information about memory, processes, paging, etc.
iostat - CPU statistics, input/output statistics for devices and partitions.

6 examples of vmstat command under Linux 1. List active and inactive memory

In the following example, 6 columns are output. The meaning of each column parsed in the man page of vmstat. The most important ones are the free attribute in the memory and the si and so attributes in the swap partition.

[root@tecmint ~]# vmstat -a
 
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
 r  b   swpd   free  inact active   si   so    bi    bo   in   cs us sy id wa st
 1  0      0 810420  97380  70628    0    0   115     4   89   79  1  6 90  3  0

Free – free memory space
•si – The amount of data swapped from disk into memory per second (in KB).
•so – The amount of data (in KB) swapped from memory to disk per second.

Note: If you execute the vmstat command without parameters, it will output a summary report since the system started.

2. Execute vmstat every X seconds, N times in total

The following command will execute vmstat every 2 seconds and will automatically stop executing after 6 times.

[root@tecmint ~]# vmstat 2 6
 
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 810420  22064 101368    0    0    56     3   50   57  0  3 95  2  0
 0  0      0 810412  22064 101368    0    0     0     0   16   35  0  0 100  0  0
 0  0      0 810412  22064 101368    0    0     0     0   14   35  0  0 100  0  0
 0  0      0 810412  22064 101368    0    0     0     0   17   38  0  0 100  0  0
 0  0      0 810412  22064 101368    0    0     0     0   17   35  0  0 100  0  0
 0  0      0 810412  22064 101368    0    0     0     0   18   36  0  1 100  0  0

3. vmstat command with timestamp

Execute the vmstat command with the -t parameter. This command will put a timestamp after each line of output, as shown below.

[tecmint@tecmint ~]$ vmstat -t 1 5
 
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------ ---timestamp---
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 0  0      0 632028  24992 192244    0    0    70     5   55   78  1  3 95  1  0        2012-09-02 14:57:18 IST
 1  0      0 632028  24992 192244    0    0     0     0  171  514  1  5 94  0  0        2012-09-02 14:57:19 IST
 1  0      0 631904  24992 192244    0    0     0     0  195  600  0  5 95  0  0        2012-09-02 14:57:20 IST
 0  0      0 631780  24992 192244    0    0     0     0  156  524  0  5 95  0  0        2012-09-02 14:57:21 IST
 1  0      0 631656  24992 192244    0    0     0     0  189  592  0  5 95  0  0        2012-09-02 14:57:22 IST
4. Statistics of various counters

The -s parameter of the vmstat command will output various event counters and memory statistics.

vmstat命令的-s参数,将输出各种事件计数器和内存的统计信息。
[tecmint@tecmint ~]$ vmstat -s
 
      1030800  total memory
       524656  used memory
       277784  active memory
       185920  inactive memory
       506144  free memory
        26864  buffer memory
       310104  swap cache
      2064376  total swap
            0  used swap
      2064376  free swap
         4539 non-nice user cpu ticks
            0 nice user cpu ticks
        11569 system cpu ticks
      329608 idle cpu ticks
         5012 IO-wait cpu ticks
           79 IRQ cpu ticks
           74 softirq cpu ticks
            0 stolen cpu ticks
       336038 pages paged in
        67945 pages paged out
            0 pages swapped in
            0 pages swapped out
       258526 interrupts
       392439 CPU context switches
   1346574857 boot time
     2309 forks

5. Disk statistics

The -d parameter of vmstat will output statistical information of all disks.

[tecmint@tecmint ~]$ vmstat -d
 
disk- ------------reads------------ ------------writes----------- -----IO------
       total merged sectors      ms  total merged sectors      ms    cur    sec
ram0       0      0       0       0      0      0       0       0      0      0
ram1       0      0       0       0      0      0       0       0      0      0
ram2       0      0       0       0      0      0       0       0      0      0
ram3       0      0       0       0      0      0       0       0      0      0
ram4       0      0       0       0      0      0       0       0      0      0
ram5       0      0       0       0      0      0       0       0      0      0
ram6       0      0       0       0      0      0       0       0      0      0
ram7       0      0       0       0      0      0       0       0      0      0
ram8       0      0       0       0      0      0       0       0      0      0
ram9       0      0       0       0      0      0       0       0      0      0
ram10      0      0       0       0      0      0       0       0      0      0
ram11      0      0       0       0      0      0       0       0      0      0
ram12      0      0       0       0      0      0       0       0      0      0
ram13      0      0       0       0      0      0       0       0      0      0
ram14      0      0       0       0      0      0       0       0      0      0
ram15      0      0       0       0      0      0       0       0      0      0
loop0      0      0       0       0      0      0       0       0      0      0
loop1      0      0       0       0      0      0       0       0      0      0
loop2      0      0       0       0      0      0       0       0      0      0
loop3      0      0       0       0      0      0       0       0      0      0
loop4      0      0       0       0      0      0       0       0      0      0
loop5      0      0       0       0      0      0       0       0      0      0
loop6      0      0       0       0      0      0       0       0      0      0
loop7      0      0       0       0      0      0       0       0      0      0
sr0        0      0       0       0      0      0       0       0      0      0
sda     7712   5145  668732  409619   3282  28884  257402  644566      0    126
dm-0   11578      0  659242 1113017  32163      0  257384 8460026      0    126
dm-1     324      0    2592    3845      0      0       0       0      0      2

6. Output statistical information in MB units

The -S and -M parameters of vmstat (uppercase and MB) will be output in MB units. vmstat outputs statistical information in KB by default.

[root@tecmint ~]# vmstat -S M 1 5
 
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    346     53    476    0    0    95     8   42   55  0  2 96  2  0
 0  0      0    346     53    476    0    0     0     0   12   15  0  0 100  0  0
 0  0      0    346     53    476    0    0     0     0   32   62  0  0 100  0  0
 0  0      0    346     53    476    0    0     0     0   15   13  0  0 100  0  0
 0  0      0    346     53    476    0    0     0     0   34   61  0  1 99  0  0
6 examples of Iostat commands under Linux 1. Output CPU and input/output (I/O) statistics

The iostat command without parameters will output the CPU and output/output statistics of each partition, as shown below.

[root@tecmint ~]# iostat
 
Linux 2.6.32-279.el6.i686 (tecmint.com)         09/03/2012      _i686_  (1 CPU)
 
avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.12    0.01    1.54    2.08    0.00   96.24
 
Device:            tps   Blk_read/s   Blk_wrtn/s   Blk_read   Blk_wrtn
sda               3.59       161.02        13.48    1086002      90882
dm-0              5.76       159.71        13.47    1077154      90864
dm-1              0.05         0.38         0.00       2576          0
2. Only output CPU statistics

The -c parameter of the iostat command only outputs CPU statistical information, as shown below.

[root@tecmint ~]# iostat -c
 
Linux 2.6.32-279.el6.i686 (tecmint.com)         09/03/2012      _i686_  (1 CPU)
 
avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.12    0.01    1.47    1.98    0.00   96.42

3. Output only the input/output statistics of the disk

The -d parameter of the iostat command only outputs the input/output statistics of all partitions of the disk, as shown below.

[root@tecmint ~]# iostat -d
 
Linux 2.6.32-279.el6.i686 (tecmint.com)         09/03/2012      _i686_  (1 CPU)
 
Device:            tps   Blk_read/s   Blk_wrtn/s   Blk_read   Blk_wrtn
sda               3.35       149.81        12.66    1086002      91746
dm-0              5.37       148.59        12.65    1077154      91728
dm-1              0.04         0.36         0.00       2576          0
4. Output only the input/output statistics of a certain disk

By default, the iostat command will output the statistical information of all partitions, but if you add the -p parameter and the disk device name after the iostat command, the command will only output the input/output statistical information of the listed disks. As follows.

[root@tecmint ~]# iostat -p sda
 
Linux 2.6.32-279.el6.i686 (tecmint.com)         09/03/2012      _i686_  (1 CPU)
 
avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.11    0.01    1.44    1.92    0.00   96.52
 
Device:            tps   Blk_read/s   Blk_wrtn/s   Blk_read   Blk_wrtn
sda               3.32       148.52        12.55    1086002      91770
sda1              0.07         0.56         0.00       4120         18
sda2              3.22       147.79        12.55    1080650      91752
5. 输出逻辑卷管理(LVM)的统计信息

iostat命令的-N(大写)参数将会输出LVM(LCTT译注:LVM是linux环境下对磁盘分区进行管理的一种机制,是磁盘分区和文件系统间的一个逻辑层)的统计信息,如下所示。

[root@tecmint ~]# iostat -N
 
Linux 2.6.32-279.el6.i686 (tecmint.com)         09/03/2012      _i686_  (1 CPU)
 
avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.11    0.01    1.39    1.85    0.00   96.64
 
Device:            tps   Blk_read/s   Blk_wrtn/s   Blk_read   Blk_wrtn
sda               3.20       142.84        12.16    1086002      92466
vg_tecmint-lv_root     5.13       141.68        12.16    1077154      92448
vg_tecmint-lv_swap     0.04         0.34         0.00       2576          0
6. iostat版本信息

iostat的-V(大写)参数将会输出iostat的版本信息,如下所示。

[root@tecmint ~]# iostat -V
 
sysstat version 9.0.4
(C) Sebastien Godard (sysstat  orange.fr)

注意:vmstat和iostat的输出中包含多列的数据和标志,限于篇幅无法在本文中进行详细的解析。如果你想知道更多的信息,请查看vmstat和iostat的man帮助手册。如果你觉得本文对你有价值,请在下面的评论框中与你的朋友分享。


The above is the detailed content of Introduction to commands for Linux performance monitoring. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:linuxprobe.com. If there is any infringement, please contact admin@php.cn delete