본문 바로가기

개발/Server Side

시스템 성능 분석 명령어 - sar, vmstat

1. sar

sar 명령어는 sysstat 패키지에 속해있다. 그러므로 시스템에 sysstat 이 설치되어 있어야 한다. 
(ubuntu : apt-get install sysstat)

sar는 CPU, 메모리, 입출력, 페이징, 네트워크, 인터럽트 등의 세세한 세스템 자원에 관한 성능 데이터를 출력하는 매우 강력한 툴이다.

sar는 성능 데이터를 수집, 보고, 저장한다. 크게 3가지 요소가 있는데 각각을 살펴보도록 하자.

1. sadc - System activity data collector
/usr/lib/sadc (System activity data collector)  
sadb 명령어는 지정된 주기마다 시스템 데이터를 수집한다. 이것은 /va/log/sa/sa[dd] 에 있는 날짜별 activity 데이터 파일을 사용한다.

2. Sa1 shell-script
/usr/lib/sa1 
sa1 스크립트는 /usr/lib/sadcs 를 호출한다. sa1 은 다음과 같이 crontab 에 의해서 실행된다.(5분마다 실행)
*/5 * * * * root /usr/lib/sa/sa1 1 1

3. Sa2 shell-script
/usr/lib/sa2

sa2는 /var/log/sa/sa[dd] 파일에 날짜별 레포트를 기록하는 스크립트이다. 다음과 같이 자정에 실행되도록 crontab을 설정한다.
59 23 * * * root /usr/lib/sa/sa2 –A

[sar 활용]
1. CPU 통계 출력 
# sar –u
Linux 2.6.32-23-generic-pae (tyolee)    2010년 08월 20일        _i686_  (1 CPU)

10시 32분 08초       LINUX RESTART

                CPU     %user     %nice   %system   %iowait    %steal     %idle
                all      0.00      0.00      0.04      0.00      0.00     99.96
                all      0.00      0.00      0.02      0.00      0.00     99.98
평균:         all      0.00      0.00      0.03      0.00      0.00     99.97

만약 CPU별로 데이터를 보고 싶으면 다음과 같이 실행한다.

# sar -u -P ALL
Linux 2.6.32-23-generic-pae (tyolee)    2010년 08월 20일        _i686_  (1 CPU)

10시 32분 08초       LINUX RESTART

                CPU     %user     %nice   %system   %iowait    %steal     %idle
                all      0.00      0.00      0.04      0.00      0.00     99.96
                  0      0.00      0.00      0.04      0.00      0.00     99.96

                CPU     %user     %nice   %system   %iowait    %steal     %idle
                all      0.00      0.00      0.02      0.00      0.00     99.98
                  0      0.00      0.00      0.02      0.00      0.00     99.98

평균:         CPU     %user     %nice   %system   %iowait    %steal     %idle
평균:         all      0.00      0.00      0.03      0.00      0.00     99.97
평균:           0      0.00      0.00      0.03      0.00      0.00     99.97


2. 디스크 입출력 통계 출력
# sar –d
Linux 2.6.32-23-generic-pae (tyolee)    2010년 08월 20일        _i686_  (1 CPU)

10시 32분 08초       LINUX RESTART

                  DEV       tps  rd_sec/s  wr_sec/s  avgrq-sz  avgqu-sz     await     svctm     %util
               dev8-0      0.02      0.00      0.17      9.45      0.00      0.00      0.00      0.00
             dev251-0      0.02      0.00      0.17      7.43      0.00      0.00      0.00      0.00
             dev251-1      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
               dev8-0      0.02      0.00      0.15      8.00      0.00      0.00      0.00      0.00
             dev251-0      0.02      0.00      0.15      7.33      0.00      0.00      0.00      0.00
             dev251-1      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
평균:        dev8-0      0.02      0.00      0.16      8.73      0.00      0.00      0.00      0.00
평균:      dev251-0      0.02      0.00      0.16      7.38      0.00      0.00      0.00      0.00
평균:      dev251-1      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00


3. 네트워크 통계 출력
# sar -n DEV
Linux 2.6.32-23-generic-pae (tyolee)    2010년 08월 20일        _i686_  (1 CPU)

10시 32분 08초       LINUX RESTART

                IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s
                   lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
                 eth1      2.52      0.00      0.23      0.00      0.00      0.00      0.00
                   lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
                 eth1      3.41      0.03      0.28      0.00      0.00      0.00      0.00
평균:            lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
평균:          eth1      2.96      0.02      0.25      0.00      0.00      0.00      0.00

# sar -n SOCK
Linux 2.6.32-23-generic-pae (tyolee)    2010년 08월 20일        _i686_  (1 CPU)

10시 32분 08초       LINUX RESTART

               totsck    tcpsck    udpsck    rawsck   ip-frag    tcp-tw
                   36         2         1         0         0         0
                   36         2         1         0         0         0
평균:            36         2         1         0         0         0


2. vmstat
vmstat은 전형적인 성능 모니터링 툴이다. 이것은 메모리, 스왑, 입출력, CPU 성능 정보 등을 보여준다.

1. vmstat을 1초 주기로 100번 실행
# vmstat 1 100
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa
 0  0      0 269688 145776  68292    0    0    62     6   13   21  0  1 99  0
 0  0      0 269680 145776  68316    0    0     0     0    9    9  0  0 100  0
 0  0      0 269680 145776  68316    0    0     0     0    8    9  0  0 100  0
 0  0      0 269680 145776  68316    0    0     0     0   11   10  0  0 100  0
.........

각각의 항목은 다음과 같은 내용이다.
Vmstat procs Section
o r field: Total number of runnable process
o b field: Total number of blocked process

Memory section
o Swpd field: Used swap space
o Free field: Available free RAM
o Buff field: RAM used for buffers
o Cache field: RAM used for filesystem cache

Swap Section
o Si field: Amount of memory swapped from disk per second
o So field: Amount of memory swapped to disk per second

IO Section
o Bi field: Blocks received from disk
o Bo field: Blocks sent to disk.

System Section
o In field: Number of interrupts per second.
o Cs field: Number of context switches per second.

CPU Section
o Us field: Time spend running user code. (non-kernel code)
o Sy field: Time spent running kernel code.
o Id field: Idle time.
o Wa field: Time spent waiting for the IO

'개발 > Server Side' 카테고리의 다른 글

커널 파라미터 변경 - sysctl  (0) 2010.03.04
네트워크 정보 출력 - netstat  (0) 2010.03.04
bash 쉘스크립트 디버깅  (0) 2010.03.04
Safe Reboot - Magic SysRq Key  (0) 2010.03.04
주기적으로 작업 실행 - cron  (0) 2010.03.04