[시스템] 리소스 모니터링[MRTG] – 아랑

<<<< LINUX 서버에 대한 리소스 모니터링  >>>>

UNIX 계열의 장비에 대한 리소스를 MRTG 를 이용하여 모니터링 하는 방법에 대해

알아보자.

필요한 것으로는 SNMP 와 MRTG 이다. 이 툴들을 설치하기 위해선 몇가지 부수적

인 프로그램이 필요하다. zlib,gd,libpng,libjpeg 등이다.

자 그럼 간단히 설치 과정을 살펴보자.

먼저 ucd-snmpd 를 설치하자. 배포판을 설치시 기본적으로 셋팅이 되어져 있는

경우도 있는데 이를 그대로 사용시에는 가끔 골치 아픈 문제가 생기게 되는 처음

부터 깔끔하게 소스로 설치하도록 하자.

먼저 패키지를 제거하고 ..

# rpm -e ucd-snmp-devel

# rpm -e ucd-snmp-utils

# rpm -e –nodeps ucd-snmp

ucd-snmp 의 사이트는 http://ucd-snmp.ucdavis.edu/이며, 최근 NET-SNMP 이라는

이름으로 바뀌었습니다.

최신버전은 http://sourceforget.net

에서 받을수 있습니다.

적절한 위치에 소스를 풀고 (난 /usr/local/src ) configure 를 한다.

# ./configure

중간에 몇가지 질문이 나온다. 적당한 정보를 입력하기 바랍니다.

System Contact Information (root@): loveme at wowlinux.com

                            …

System Location (Unknown): wowlinux/seoul/korea

                            ….

# make

# umask 022

# make install

Perl/SNMP 모듈인스톨을 하자.

ucd-snmp/perl/SNMP 디렉토리내에 Perl/SNMP 모듈이 포함되어져 있으므로함께

인스톨 해야 한다.

# cd perl/SNMP/

# perl Makefile.PL

# make

# make test

# make install

테스트 중간에 1~2개 정도 실패할수도 있지만 설치에는 큰 문제는 없다.

snmp 설치가 끝났으면 snmpd 데몬을 실행하고 확인한다.

이상 기본 설정으로는 snmp 서비스를 이용할수 있는것은 localhost 와

public 커뮤니티 뿐이다. 하지만 이는 표준화 되어져 있으므로 보안상

꼭 커뮤니티는 바꾸어 주어야 한다.

snmp 소스 디렉토리에서

# cp EXAMPLE.conf /usr/local/share/snmp/snmpd.conf

# cd /usr/local/share/snmp

# vi snmpd.conf

—————————————————————————–

.

.

####

# First, map the community name (COMMUNITY) into a security name

# (local and mynetwork, depending on where the request is coming

# from):

#       sec.name  source          community

com2sec local     localhost       xxxxxxxxxxxxx

com2sec mynetwork NETWORK/24      xxxxxxxxxxxxx

.

.

—————————————————————————–

이시스템 자체에서 모니터툴인 MRTG 가 설치 되어져 있는 경우에는 local 부분의

community 를 바꾸어 주어야 하고, 원격 시스템에 MRTG 가 설치되어져 있는 경우

에는 mynetwork 부분의 NETWOK/24 부분에 원격시스템의 주소를 적어주고 community

를 변경해 주면 된다.

자 이제 snmp 의 동작유무를 확인합니다.

# snmpwalk localhost xxxxxxxxxxxx system

                     ————

                    (춤ommunity )

여러가지 시스템 정보가 출력되면 정상입니다.

MRTG 설치

먼저 MRTG 를 설치하기 위해서 apache+PHP 에 gd 와 libpng,zlib가 연동되어져

있어야 합니다. 그런후 MRTG 를 설치하시는게 좋을것입니다.

MRTG 설치전에 몇가지 확인을 해보자.

PERL 확인 : perl 5.005 이후

zlib 설치유무

libpng 설치유무

gd 설치유무 (/usr/local/gd 에서 ./configure && make && make install)

탨MRTG 설치 (/usr/local에서 작업)

# tar xzvf mrtg-2.9.10.tar.gz

# mv mrtg-2.9.10 mrtg

# cd mrtg

# ./configure –with-gd=/usr/local/gd –with-zlib=/usr/lib \\

              –with-libpng=/usr/lib

(보통 rpm 으로 설치시 /usr/lib 에 zlib,libpng 등의 라이브러리가 있다.

만일 소스로 직접 설치시에는 설치 경로를 적어주면 된다.)

# make

MRTG 가 이상없이설치 완료 되었으면 bin 디렉토리 밑에 mrtg,cfgmaker 와

같은 실행파일이 만들어 져 있다.

cfg 파일 생성

# cd bin

# ./cfgmaker xxxxxxx@localhost (xxxxxxx는 snmp 설치시 community 이고 localhost

에는 ip address 혹은 domain name 을 적어준다. )

그러면 앞으로 만들어질 cfg 파일의 내요이 보일것이다. 만일

SNMPWALK Problem for 1.3.6.1.2.1.2.2.1.3 on xxxxxxxxx@localhost:

와 같은 메세지가 뜨면 이는 community 가 틀리거나 snmp 데몬이 정상적으로 동작

하지 않는 경우이다. 앞의 셋팅 과정에 이상이 없는지 확인하라.

정상적으로 나오면 cfg 파일을 만들어 보자.

# ./cfgmaker xxxxxxxx@localhost > mrtg.cfg

# vi mrtg.cfg (몇가지 수정 추가를 해준다. )

Language: korean (사용언어)

Options[_]: bits

WorkDir: /home/xxxx/www/mrtg ( mrtg 정보를 보여줄 홈페이지 절대경로)

등을 추가 한다.

그리고 리포트가 만들어질 작업 디렉토리를 생성해주고 apache 를 셋팅해준다.

# mkdir /home/xxxxx/www/mrtg

그런후 mrtg 를 실행한다.

# ./mrtg mrtg.cfg

위 명령을 치면 처음에 몇가지 warning 메세지가 뜨는데 이는 비교할수 있는

log 값이 없기 때문에 나타나는 것으로 위명령을 2,3 번 정도 반복하면 더이상

나오지 않을것이다.

이제 주기적으로mrtg 를 실행할수 있도록 cron 데몬에 등록 시켜주면 된다.

cpu 와 메모리 등도 모니터링이 가능한데 이는 여러가지 기반 지식이 필요하니

전제적은 설명은 생략하고 다음 cfg 파일을 이용하도록 하자.

CPU 모니터링

먼저 CPU 는 snmp 의 mib 에서 정보유출 형식이 소수점으로 나오기 때문에 100을

곱하여 백분율식으로 변경해 주어야 한다. 그레서 perl 스크립트를 이용하여 사용

하도록 한다.

# vi cpumonitoring.pl

—————————————————————————-

#!/usr/bin/perl

system “/usr/local/bin/snmpget 211.201.133.135 \\

muchunalang .1.3.6.1.4.1.2021.10.1.3.1 | awk ‘{print \\$3}’ >  temp”;

system “/usr/local/bin/snmpget 211.201.133.135 \\

muchunalang .1.3.6.1.4.1.2021.10.1.3.2 | awk ‘{print \\$3}’ >>  temp”;

open(fileHandle, “<temp”) || die “Cannot open $fileName.\\n”;

$value1=<fileHandle>;

$value2=<fileHandle>;

chop($value1);

chop($value2);

close(fileHandle);

$one_minute = $value1 * 100;

$five_minute = $value2 * 100;

print “$one_minute\\n$five_minute\\n”;

——————————————————————————-

# chmod 755 cpumonitoring.pl

# vi cpu.mrtg

——————————————————————————-

#######################################################################

#   CPU load config for www3

#

Target[cpu]:’/usr/local/mrtg/bin/cpumonitoring.pl’

Language: korean

WorkDir: /home/muchun/www/mrtg

Options[cpu]: growright, gauge, absolute, nopercent

MaxBytes[cpu]: 100

Title[cpu]: CPU 평균사용률

Ylegend[cpu]: Load Avg

ShortLegend[cpu]: %

Legend1[cpu]: 1min. CPU load average

Legend2[cpu]: 5min. CPU load average

LegendI[cpu]:  1min:

LegendO[cpu]: 5min:

PageTop[cpu]:<H1>CPU 평균 사용률</H1>

        <table>

        <tr><td>System:</td><td>RedHat 7.0</td></tr>

      

<tr><td>Variables:</td><td>Green:1분평균,Blue:5분평균</td></tr>

        </table>

#######################################################################

#   CPU load config for www3

#

Target[cpu]:’/usr/local/mrtg/bin/cpumonitoring.pl’

Language: korean

WorkDir: /home/muchun/www/mrtg

Options[cpu]: growright, gauge, absolute, nopercent

MaxBytes[cpu]: 100

Title[cpu]: CPU 평균사용률

Ylegend[cpu]: Load Avg

ShortLegend[cpu]: %

Legend1[cpu]: 1min. CPU load average

Legend2[cpu]: 5min. CPU load average

LegendI[cpu]:  1min:

LegendO[cpu]:  5min:

PageTop[cpu]:<H1>CPU 평균 사용률</H1>

        <table>

        <tr><td>System:</td><td>RedHat 7.0</td></tr>

      

<tr><td>Variables:</td><td>Green:1분평균,Blue:5분평균</td></tr>

        </table>

——————————————————————————-

# ./mrtg cpu.cfg

메모리 모니터링

# vi mem.cfg

——————————————————————————

#######################################################################

#   memory load config for zzang911.net

#

Target[mem]:.1.3.6.1.4.1.2021.4.4.0&.1.3.6.1.4.1.2021.4.6.0:muchunalang@zzang911

.net

Language: korean

WorkDir: /home/muchun/www/mrtg

Options[mem]: growright, gauge, absolute, nopercent

MaxBytes[mem]: 646864

Title[mem]: Memory 평균사용률

Ylegend[mem]: Avaiable memory

ShortLegend[mem]:  

kilo[mem]: 1024

KMG[mem]: ,M,G,T,P

Legend1[mem]: swap free

Legend2[mem]: real free

LegendI[mem]:  swap

LegendO[mem]:  real

PageTop[mem]:<H1>Memory 사용률 모니터링 </H1>

        <table>

        <tr><td>System:</td><td>RedHat 7.0</td></tr>

        <tr><td>Totals:</td><td>Real = 640MBytes and Swap =

600MBytes </td></tr>

        <tr><td>Variables:</td><td>Avaiable memory: Real and

Swap</td></tr>

       </table>

——————————————————————————-

# ./mrtg mem.cfg

이와 같이 하면 모니터링이 가능하다.

그럼…이만..휘리릭~~~~

서진우

슈퍼컴퓨팅 전문 기업 클루닉스/ 상무(기술이사)/ 정보시스템감리사/ 시스존 블로그 운영자

You may also like...

2 Responses

  1. 2022년 6월 21일

    1agency

  2. 2023년 1월 26일

    3tuition

페이스북/트위트/구글 계정으로 댓글 가능합니다.