UNIX/Redhat

[스크랩] 리눅스 모니터링 툴 18개

99iberty 2013. 12. 13. 10:56

http://iprize.tistory.com/643

 

 

리눅스 서버 성능을 모니터링해야 하나요? 내장 명령어와 몇 가지 add-on 툴을 사용해 보라. 대부분의 리눅스 배포판은 매우 많은 모니터링 도구를 가지고 있다. 이들 도구는 시스템 작동에 대한 정보를 수집하는 데 사용되는 방법을 제공한다. 이들 도구를 이용하여 성능 문제의 잠재적인 원인을 알아낼 수 있다. 아래 설명하는 기본 명령어들은 시스템 분석이나 서버 이슈를 추적할 때 사용되는 것들이다.

1. 병목 현상 검색

2. 디스크 병목 현상

3. CPU와 메모리 병목현상

4. 네트워크 병목 현상

1. Top - 프로세스 작업 명령어

top 프로그램은 실제 프로세스 작업과 같은 운영 시스템의 실시간 정보를 제공한다. 기본적으로 서버에서 실행되는 CPU 사용 비율을 표시하며 매 5초마다 정보를 갱신한다.

자주 사용되는 단축키

top 명령어는 여러 유용한 단축키를 가진다.

단축키 설명

t 요약 정보 표시

m 메모리 정보 표시

A 시스템 자원을 많이 소모하는 프로세스를 정렬한다. 시스템의 성능을 소모시키를 프로세스를 파악할 때 유용하다.

f top의 설정 화면을 표시한다. 특정 태스크를 위해 top을 설정할 때 유용하다.

o top의 정렬 순서를 정할 수 있다.

r renice 명령어를 실행한다.

k kill 명령어를 실행한다.

z color/mono를 전환한다.

연관 정보 : How do I Find Out Linux CPU Utilization?

2. vmstat - 시스템 작업, 하드웨어 및 시스템 정보

vmstat은 프로세스, 메모리, 페이징, 블록 IO, 트랩 및 cpu 작업에 관한 정보를 표시한다.

# 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
0 0 0 2540988 522188 5130400 0 0 2 32 4 2 4 1 96 0 0
1 0 0 2540988 522188 5130400 0 0 0 720 1199 665 1 0 99 0 0
0 0 0 2540956 522188 5130400 0 0 0 0 1151 1569 4 1 95 0 0
0 0 0 2540956 522188 5130500 0 0 0 6 1117 439 1 0 99 0 0
0 0 0 2540940 522188 5130512 0 0 0 536 1189 932 1 0 98 0 0
0 0 0 2538444 522188 5130588 0 0 0 0 1187 1417 4 1 96 0 0
0 0 0 2490060 522188 5130640 0 0 0 18 1253 1123 5 1 94 0 0

메모리 사용량 표시

# vmstat -m

활성/비활성 메모리 페이지 정보 표시

# vmstat -a

3. w - 누가 로그인했고 무엇을 하고 있는가 알아내기

w 명령어는 현재 시스템에 로그인한 사용자와 프로세스를 표시한다.

# w username

# w vivek

4. uptime - 얼마나 오래 시스템이 운영되었는지 알아내기

uptime 명령어는 얼마나 오래 서버가 운영되고 있는지 알기 위해 사용된다. 현재 시스템이 얼마나 운영되고 있는지, 몇 명의 사용자가 로그인하고 있는지 과거 1, 5, 15분 동안의 시스템 평균 부하를 표시한다.

# uptime

출력:

18:02:41 up 41 days, 23:42, 1 user, load average: 0.00, 0.00, 0.00

수치 1은 부하 값 중 최적값으로 볼 수 있다. 부하는 시스템마다 다를 수 있지만 단일 CPU 시스템은 1-3, SMP 시스템은 6-10까지의 값을 적합한 수치로 볼 수 있다.

5. ps - 프로세스 표시하기

ps 명령어는 현재 프로세스의 상태를 보여준다. 전체 프로세스를 보기 위해 -A나, -e 옵션을 사용하라.

# ps -A

출력 예:

PID TTY TIME CMD
1 ? 00:00:02 init
2 ? 00:00:02 migration/0
3 ? 00:00:01 ksoftirqd/0
4 ? 00:00:00 watchdog/0
5 ? 00:00:00 migration/1
6 ? 00:00:15 ksoftirqd/1
....
.....
4881 ? 00:53:28 java
4885 tty1 00:00:00 mingetty
4886 tty2 00:00:00 mingetty
4887 tty3 00:00:00 mingetty
4888 tty4 00:00:00 mingetty
4891 tty5 00:00:00 mingetty
4892 tty6 00:00:00 mingetty
4893 ttyS1 00:00:00 agetty
12853 ? 00:00:00 cifsoplockd
12854 ? 00:00:00 cifsdnotifyd
14231 ? 00:10:34 lighttpd
14232 ? 00:00:00 php-cgi
54981 pts/0 00:00:00 vim
55465 ? 00:00:00 php-cgi
55546 ? 00:00:00 bind9-snmp-stat
55704 pts/1 00:00:00 ps

ps는 top과 비슷하지만 더 많은 정보를 제공한다.

자세한 출력

# ps -Al

더 자세한 출력 표시하기(이 모드에서는 프로세스에 전달된 인자까지 보일 것이다)

# ps -AlF

쓰레드 표시하기(LWP와 NLWP)

# ps -AlFH

프로세스 뒤에 쓰레드 표시하기

# ps -AlLm

서버의 모든 프로세스 표시하기

# ps ax
# ps axu

프로세스 트리 표시하기

# ps -ejH
# ps axjf
# pstree

보안 정보 표시하기

# ps -eo euser,ruser,suser,fuser,f,comm,label
# ps axZ
# ps -eM

Vivek 사용자가 실행한 프로세스 출력하기

# ps -U vivek -u vivek u

출력 형식 지정하기

# ps -eo pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,wchan:14,comm
# ps axo stat,euid,ruid,tty,tpgid,sess,pgrp,ppid,pid,pcpu,comm
# ps -eopid,tt,user,fname,tmout,f,wchan

Lighttpd의 프로세스 ID 표시하기

# ps -C lighttpd -o pid=

또는

# pgrep lighttpd

또는

# pgrep -u vivek php-cgi

PID 55977의 프로세스명 출력하기

# ps -p 55977 -o comm=

메모리 사용량 Top 10 프로세스 찾기

# ps -auxf | sort -nr -k 4 | head -10

CPU 사용량 Top 10 프로세스 찾기

# ps -auxf | sort -nr -k 3 | head -10

6. free - 메모리 사용량

free 명령어는 커널이 차지하는 버퍼뿐 아니라 시스템에서 물리 메모리, swap 메모리의 사용량, 여유량을 표시한다.

# free

결과

total used free shared buffers cached
Mem: 12302896 9739664 2563232 0 523124 5154740
-/+ buffers/cache: 4061800 8241096
Swap: 1052248 0 1052248

관련글 :

  1. Linux Find Out Virtual Memory PAGESIZE
  2. Linux Limit CPU Usage Per Process
  3. How much RAM does my Ubuntu / Fedora Linux desktop PC have?

7. iostat - 평균 CPU 부하 및 디스크 활동

iostat 명령어는 CPU 통계 및 장치, 파티션, 네트워크 파일시스템(NFS)의 입출력 통계를 보고한다.

# iostat

결과

Linux 2.6.18-128.1.14.el5 (www03.nixcraft.in) 06/26/2009
avg-cpu: %user %nice %system %iowait %steal %idle
3.50 0.09 0.51 0.03 0.00 95.86
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 22.04 31.88 512.03 16193351 260102868
sda1 0.00 0.00 0.00 2166 180
sda2 22.04 31.87 512.03 16189010 260102688
sda3 0.00 0.00 0.00 1615 0

관련글 : Linux Track NFS Directory / Disk I/O Stats

8.sar - 시스템 활동 수집 및 보고

sar 명령어는 시스템 활동 정보를 수집하고 보고하며 저장할 때 사용된다. 네트워크 카운터를 보기 위해서는 아래와 같이 입력한다.

# sar -n DEV | more

sar를 이용해서 실시간 사용량을 출력할 수 있다.

# sar 4 5

출력

Linux 2.6.18-128.1.14.el5 (www03.nixcraft.in) 06/26/2009
06:45:12 PM CPU %user %nice %system %iowait %steal %idle
06:45:16 PM all 2.00 0.00 0.22 0.00 0.00 97.78
06:45:20 PM all 2.07 0.00 0.38 0.03 0.00 97.52
06:45:24 PM all 0.94 0.00 0.28 0.00 0.00 98.78
06:45:28 PM all 1.56 0.00 0.22 0.00 0.00 98.22
06:45:32 PM all 3.53 0.00 0.25 0.03 0.00 96.19
Average: all 2.02 0.00 0.27 0.01 0.00 97.70

관련 글 : How to collect Linux system utilization data into a file

9. mpstat - Multiprocessor 사용량

mpstat 명령어는 각 사용 가능한 프로세서의 활동 상황을 표시한다. 프로세서 0은 첫 번째 프로세서를 나타낸다. mpstat -P ALL은 프로세서당 평균 CPU 사용량을 나타낸다.


# mpstat -P ALL


출력 :

Linux 2.6.18-128.1.14.el5 (www03.nixcraft.in) 06/26/2009

06:48:11 PM  CPU   %user   %nice    %sys %iowait    %irq   %soft  %steal   %idle    intr/s
06:48:11 PM  all    3.50    0.09    0.34    0.03    0.01    0.17    0.00   95.86   1218.04
06:48:11 PM    0    3.44    0.08    0.31    0.02    0.00    0.12    0.00   96.04   1000.31
06:48:11 PM    1    3.10    0.08    0.32    0.09    0.02    0.11    0.00   96.28     34.93
06:48:11 PM    2    4.16    0.11    0.36    0.02    0.00    0.11    0.00   95.25      0.00
06:48:11 PM    3    3.77    0.11    0.38    0.03    0.01    0.24    0.00   95.46     44.80
06:48:11 PM    4    2.96    0.07    0.29    0.04    0.02    0.10    0.00   96.52     25.91
06:48:11 PM    5    3.26    0.08    0.28    0.03    0.01    0.10    0.00   96.23     14.98
06:48:11 PM    6    4.00    0.10    0.34    0.01    0.00    0.13    0.00   95.42      3.75
06:48:11 PM    7    3.30    0.11    0.39    0.03    0.01    0.46    0.00   95.69     76.89


관련글 : Linux display each multiple SMP CPU processors utilization individually.


10. pmap - 프로세스 메모리 사용량


pmap 명령은 프로세스의 메모리 지도를 표시한다. 이 명령어를 사용하여 메모리 병목현상의 원인을 찾기 위해 사용한다.


# pmap -d PID


pid # 47394의 프로세스 메모리 정보를 표시하기 위해서는,


# pmap -d 47394


출력 :


47394: /usr/bin/php-cgi

Address           Kbytes Mode  Offset           Device    Mapping
0000000000400000    2584 r-x-- 0000000000000000 008:00002 php-cgi
0000000000886000     140 rw--- 0000000000286000 008:00002 php-cgi
00000000008a9000      52 rw--- 00000000008a9000 000:00000   [ anon ]
0000000000aa8000      76 rw--- 00000000002a8000 008:00002 php-cgi
000000000f678000    1980 rw--- 000000000f678000 000:00000   [ anon ]
000000314a600000     112 r-x-- 0000000000000000 008:00002 ld-2.5.so
000000314a81b000       4 r---- 000000000001b000 008:00002 ld-2.5.so
000000314a81c000       4 rw--- 000000000001c000 008:00002 ld-2.5.so
000000314aa00000    1328 r-x-- 0000000000000000 008:00002 libc-2.5.so
000000314ab4c000    2048 ----- 000000000014c000 008:00002 libc-2.5.so
.....
......
..
00002af8d48fd000       4 rw--- 0000000000006000 008:00002 xsl.so
00002af8d490c000      40 r-x-- 0000000000000000 008:00002 libnss_files-2.5.so
00002af8d4916000    2044 ----- 000000000000a000 008:00002 libnss_files-2.5.so
00002af8d4b15000       4 r---- 0000000000009000 008:00002 libnss_files-2.5.so
00002af8d4b16000       4 rw--- 000000000000a000 008:00002 libnss_files-2.5.so
00002af8d4b17000  768000 rw-s- 0000000000000000 000:00009 zero (deleted)
00007fffc95fe000      84 rw--- 00007ffffffea000 000:00000   [ stack ]
ffffffffff600000    8192 ----- 0000000000000000 000:00000   [ anon ]
mapped: 933712K    writeable/private: 4304K    shared: 768000K


가장 마지막 라인에 주목하라.


  • mapped: 933712K 파일에 매핑된 메모리 총량

  • writable/private: 4304K 전용 주소 공간의 양

  • shared: 768000K 다른 프로세스와 공유하는 주소 공간의 양


관련글 : Linux find the memory used by a program / process using pmap command


11/12. netstat 와 ss - 네트워크 통계


이 명령어는 네트워크 연결, 라우팅 테이블, 인터페이스 통계, 마스커레이드 연결, 멀티캐스트 멤버쉽 등을 표시한다. ss는 소켓 통계를 추출하는 데 사용된다. netstat와 유사한 정보를 보여준다.


13. iptraf - 실시간 네트워크 통계


iptraf 명령어는 IP LAN 모니터링 도구이다. IP LAN은 ncurses 기반으로 TCP 정보, UDP, ICMP/OSPF 정보, 이더넷 부하, 노드 상태, IP 체크섬 에러 등의 네트워크 통계 정보를 생성한다. 다음의 정보들을 보기 편한 형태로 보고서를 만들어 낸다.


  • TCP 연결의 네트워크 트래픽 통계

  • 네트워크 카드의 IP 트래픽 통계

  • 프로토콜의 네트워크 트래픽 통계

  • TCP/UDP 포트와 패킷 크기에 따른 네트워크 트래픽 통계

  • 네트워크 2계층의 네트워크 트래픽 통계






14. tcpdump - 네트워크 트래픽 분석기


tcp 명령은 네트워크 상의 트래픽 정보를 추출하는 간단한 도구이다. 하지만 이 툴을 사용하기 위해서는 TCP/IP에 대한 이해가 필요하다. 예를 들면, DNS에 대한 트래픽 정보를 표시하기 위해서는:


# tcpdump -i eth1 'udp port 53'


80 포트를 지나는 모든 IPv4 HTTP 패킷 중 데이터를 포함하는 패킷, 즉, SYN, FIN 패킷이나 ACK 패킷을 제외한 패킷을 표시하기 위해서는:


# tcpdump 'tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) !=0)'


202.54.1.5로 나가는 모든 FTP 세션을 표시하기 위해서는:


# tcpdump -i eth1 'dst 202.54.1.5 and (port 21 or 20)'


192.168.1.5로 나가는 모든 HTTP 세션을 표시하기 위해서는


# tcpdump -ni eth0 'dst 192.168.1.5 and tcp and port http'


자세한 정보를 보기 위해 파일을 볼 때는 Wireshark를 사용하며 다음과 같이 입력한다.


# tcpdump -n -i eth1 -s 0 -w output.txt src or dst port 80


15. strace - 시스템 호출


이 명령어는 시스템 호출과 시그널을 추적한다. 이 명령어는 웹서버와 다른 서버 문제를 디버깅하는 데 유용하다. 사용법은 을 참고하라.


16. /Proc 파일 시스템 - 커널 통계


/proc 파일 시스템은 하드웨어 장치와 다른 리눅스 커널 정보에 대한 정보를 제공한다. 자세한 정보는 Linux kernel /proc

을 참고하기 바란다.


예:

# cat /proc/cpuinfo

# cat /proc/meminfo

# cat /proc/zoneinfo

# cat /proc/mounts


17. Nagios - 서버 및 네트워크 모니터링


Nagios는 오픈 소스로 컴퓨터 시스템과 네트워크를 모니터링하는 소프트웨어이다. 이 툴을 사용하여 호스트 컴퓨터와 네트워크 장비 및 서비스들을 모니터할 수 있다. 시스템에 이상이 생겼을 때 경고를 보내며 이상이 복구되면 다시 경고를 보낸다. FAN은 "Full Automated Nagios"를 뜻한다. FAN의 목표는 Nagios 커뮤니티가 제공하는 거의 모든 툴을 포함하는 Nagios를 제공하는 것이다. FAN은 표준 ISO 포맷의 CD롬 이미지를 제공하여 Nagios 서버 구축을 용이하게 한다. 이에 더해, 여러 배포판에 여러 툴들을 포함하여 Nagios에 대한 사용자 경험을 개선한다.


18. Cacti - 웹 기반 모니터링 툴


Cacti는 RRDTool의 데이터 스토리지 및 그래픽 기능을 이용한 네트워크 모니터링 솔루션이다. Cacti는 빠른 데이터 수집기, 개선된 그래프 템플릿, 다수의 데이터 수집 기법, 사용자 관리 기능을 제공한다. 이들 기능은 직관적이며 사용하기 편한 인터페이스로 수 백개의 장비로 구성된 복잡한 네트워크에 알맞다. Nagios는 네트워크, CPU, 메모리, 로그인 사용자, 아파치, DNS 서버 등에 관한 데이터를 제공한다. CentOS/RHEL에서 Cacti를 설치하고 설정하는 방법은 이곳을 참고한다.



원문 : http://www.cyberciti.biz/tips/top-linux-monitoring-tools.html

 

 

 

 

#19: KDE System Guard - Real-time Systems Reporting and Graphing

KSysguard is a network enabled task and system monitor application for KDE desktop. This tool can be run over ssh session. It provides lots of features such as a client/server architecture that enables monitoring of local and remote hosts. The graphical front end uses so-called sensors to retrieve the information it displays. A sensor can return simple values or more complex information like tables. For each type of information, one or more displays are provided. Displays are organized in worksheets that can be saved and loaded independently from each other. So, KSysguard is not only a simple task manager but also a very powerful tool to control large server farms.

Fig.05 KDE System Guard

Fig.05 KDE System Guard {Image credit: Wikipedia}

See the KSysguard handbook for detailed usage.

#20: Gnome System Monitor - Real-time Systems Reporting and Graphing

The System Monitor application enables you to display basic system information and monitor system processes, usage of system resources, and file systems. You can also use System Monitor to modify the behavior of your system. Although not as powerful as the KDE System Guard, it provides the basic information which may be useful for new users:

  • Displays various basic information about the computer's hardware and software.
  • Linux Kernel version
  • GNOME version
  • Hardware
  • Installed memory
  • Processors and speeds
  • System Status
  • Currently available disk space
  • Processes
  • Memory and swap space
  • Network usage
  • File Systems
  • Lists all mounted filesystems along with basic information about each.
Fig.06 The Gnome System Monitor application

Fig.06 The Gnome System Monitor application

Bonus: Additional Tools

A few more tools:

  • nmap - scan your server for open ports.
  • lsof - list open files, network connections and much more.
  • ntop web based tool - ntop is the best tool to see network usage in a way similar to what top command does for processes i.e. it is network traffic monitoring software. You can see network status, protocol wise distribution of traffic for UDP, TCP, DNS, HTTP and other protocols.
  • Conky - Another good monitoring tool for the X Window System. It is highly configurable and is able to monitor many system variables including the status of the CPU, memory, swap space, disk storage, temperatures, processes, network interfaces, battery power, system messages, e-mail inboxes etc.
  • GKrellM - It can be used to monitor the status of CPUs, main memory, hard disks, network interfaces, local and remote mailboxes, and many other things.
  • vnstat - vnStat is a console-based network traffic monitor. It keeps a log of hourly, daily and monthly network traffic for the selected interface(s).
  • htop - htop is an enhanced version of top, the interactive process viewer, which can display the list of processes in a tree form.
  • mtr - mtr combines the functionality of the traceroute and ping programs in a single network diagnostic tool.