웹사이트 검색

초보자를 위한 Linux vmstat 명령 자습서(예제 5개)


이 페이지에서

  1. Linux vmstat 명령
  2. Q1. vmstat를 사용하는 방법?\n
  3. Q2. vmstat가 출력을 자동 업데이트하게 만드는 방법은 무엇입니까?\n
  4. Q3. vmstat 디스플레이 slabinfo를 만드는 방법은 무엇입니까?\n
  5. Q4. vmstat 보고서 디스크 활동 요약 통계를 만드는 방법은 무엇입니까?\n
  6. Q5. vmstat가 각 출력 라인에 타임 스탬프를 추가하는 방법은 무엇입니까?\n
  7. 결론

프로세스, CPU 활동, 메모리 등에 대한 정보에 액세스하는 데 사용할 수 있는 명령줄 유틸리티를 찾고 있다면 vmstat가 이 작업을 수행한다는 사실에 기뻐할 것입니다.

이 기사에서는 이해하기 쉬운 몇 가지 예를 사용하여 이 도구의 기본 사항에 대해 설명합니다. 그러나 그 전에 이 기사의 모든 예제는 Ubuntu 20.04 LTS 시스템에서 테스트되었지만 CentOS 및 Debian에서도 작동한다는 점을 언급할 가치가 있습니다.

리눅스 vmstat 명령어

Linux의 vmstat 명령은 가상 메모리 통계를 보고합니다. 구문은 다음과 같습니다.

vmstat [options] [delay [count]]

도구 매뉴얼 페이지에서 설명하는 방법은 다음과 같습니다.

       vmstat  reports  information about processes, memory, paging, block IO,
       traps, disks and cpu activity.

       The first report produced gives averages since the last reboot.   Addi?
       tional  reports  give information on a sampling period of length delay.
       The process and memory reports are instantaneous in either case.

다음은 vmstat 명령이 작동하는 방식에 대한 더 나은 아이디어를 제공하는 몇 가지 Q&A 스타일의 예입니다.

Q1. vmstat를 사용하는 방법?

기본 사용을 위해 vmstat sans 옵션을 실행하십시오.

vmstat

예를 들어 내 경우 위의 명령은 다음과 같은 출력을 생성했습니다.

procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 1  0      0 401160 100252 1307468    0    0     5    17   49   70  0  0 100  0  0

첫 번째 행에서 알 수 있듯이 출력은 6개 섹션으로 나뉩니다. 도구 매뉴얼 페이지에는 이러한 값에 대한 자세한 정보가 포함되어 있습니다. 발췌 내용은 다음과 같습니다.

Procs
       r: The number of runnable processes (running or waiting for run time).
       b: The number of processes in uninterruptible sleep.

   Memory
       swpd: the amount of virtual memory used.
       free: the amount of idle memory.
       buff: the amount of memory used as buffers.
       cache: the amount of memory used as cache.
       inact: the amount of inactive memory.  (-a option)
       active: the amount of active memory.  (-a option)

   Swap
       si: Amount of memory swapped in from disk (/s).
       so: Amount of memory swapped to disk (/s).

   IO
       bi: Blocks received from a block device (blocks/s).
       bo: Blocks sent to a block device (blocks/s).

   System
       in: The number of interrupts per second, including the clock.
       cs: The number of context switches per second.

   CPU
       These are percentages of total CPU time.
       us: Time spent running non-kernel code.  (user time, including nice time)
       sy: Time spent running kernel code.  (system time)
       id: Time spent idle.  Prior to Linux 2.5.41, this includes IO-wait time.
       wa: Time spent waiting for IO.  Prior to Linux 2.5.41, included in idle.
       st: Time stolen from a virtual machine.  Prior to Linux 2.6.11, unknown.

Q2. vmstat가 출력을 자동 업데이트하게 만드는 방법은 무엇입니까?

기본적으로 vmstat는 출력을 한 번 생성합니다. 그러나 vmstat가 출력을 자동으로 업데이트하도록 하려면 명령에 대한 입력으로 숫자 값을 지정하여 이를 수행할 수 있습니다.

이 숫자 값은 출력이 업데이트된 후 지연(초) 역할을 합니다. 예를 들어:

vmstat 3

이렇게 하면 vmstat 출력이 3초마다 새로 고쳐집니다.

procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 1  0      0 410928 100276 1307480    0    0     5    17   49   70  0  0 100  0  0
 0  0      0 410920 100284 1307480    0    0     0   181  108  143  0  0 100  0  0
 0  0      0 410920 100292 1307480    0    0     0     7   92  132  0  0 100  0  0
 0  0      0 410920 100292 1307480    0    0     0     0   87  124  0  0 100  0  0
...
...
...

Q3. vmstat 디스플레이 slabinfo를 만드는 방법은 무엇입니까?

slabinfo의 경우 -m 명령줄 옵션을 사용해야 합니다. 이 옵션이 작동하려면 Linux 배포판 커널이 slabinfo를 지원해야 합니다. 지원이 있는 경우 sudo 권한으로 명령어를 실행해야 합니다.

sudo vmstat -m

예를 들어 제 경우 생성된 출력의 일부는 다음과 같습니다.

Cache                       Num  Total   Size  Pages
ufs_inode_cache               0      0    808     40
qnx4_inode_cache              0      0    680     48
hfsplus_attr_cache            0      0   3840      8
hfsplus_icache                0      0    896     36
hfs_inode_cache               0      0    832     39
minix_inode_cache             0      0    672     48
ntfs_big_inode_cache          0      0    960     34
ntfs_inode_cache              0      0    296     55
jfs_ip                        0      0   1280     25
xfs_dqtrx                     0      0    528     31
xfs_dquot                     0      0    496     33
xfs_buf                       0      0    384     42
xfs_rui_item                  0      0    696     47
xfs_rud_item                  0      0    176     46
xfs_inode                     0      0   1024     32
xfs_efd_item                  0      0    440     37
xfs_buf_item                  0      0    272     30
xfs_trans                     0      0    232     35
xfs_da_state                  0      0    480     34
xfs_btree_cur                 0      0    224     36
...
...
...

Q4. vmstat 보고서 디스크 활동 요약 통계를 만드는 방법은 무엇입니까?

-D 명령줄 옵션을 사용하십시오.

vmstat -D

다음은 이 명령이 내 시스템에서 생성한 출력입니다.

           10 disks
            2 partitions
        15066 total reads
         5937 merged reads
      1272794 read sectors
        20063 milli reading
       155026 writes
       103687 merged writes
      4602472 written sectors
       105279 milli writing
            0 inprogress IO
          126 milli spent IO

Q5. vmstat가 각 출력 라인에 타임 스탬프를 추가하는 방법은 무엇입니까?

vmstat 명령이 각 출력 행에 타임스탬프를 추가하는지 확인하려면 -t 명령행을 사용하십시오.

vmstat -t
$ vmstat 2 -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                 UTC
 2  0      0 410116 100432 1308160    0    0     5    17   49   70  0  0 100  0  0 2020-05-08 09:40:05
 0  0      0 410116 100432 1308160    0    0     0    88  100  136  0  0 100  0  0 2020-05-08 09:40:07
 0  0      0 410116 100440 1308160    0    0     0    18   90  139  0  0 100  0  0 2020-05-08 09:40:09
 0  0      0 410116 100440 1308160    0    0     0     0   93  126  0  0 100  0  0 2020-05-08 09:40:11
 0  0      0 410368 100448 1308160    0    0     0    10  107  144  0  0 100  0  0 2020-05-08 09:40:13
 0  0      0 410368 100448 1308160    0    0     0     0   86  122  0  0 100  0  0 2020-05-08 09:40:15
 0  0      0 410368 100448 1308160    0    0     0     0  101  135  0  0 100  0  0 2020-05-08 09:40:17

강조 표시된 항목은 각 라인에 포함된 타임스탬프를 보여줍니다.

결론

Linux 명령줄에서 수행하는 작업의 종류에 따라 vmstat 명령이 실제로 도움이 될 수 있습니다. 여기에서 설명한 옵션 외에도 이 도구가 제공하는 다른 많은 명령줄 옵션이 있습니다. 자세히 알아보려면 여기로 이동하세요.