4,506,195 th visitor since 2017.2.1 ( Today : 5957 )
Computer ???
No. 271
Name. swindler
Subject. UNIX 및 Linux 서버에 대한 Resource 모니터링
Main Cate. Linux
Sub Cate.
Date. 2007-11-28 14:52
Hit. 4797 (211.36.27.8)
File.
UNIX 및 Linux 서버에 대한 Resource 모니터링

(CPU, Memory, Disk)


Unix계열(Linux포함)의 장비에 대한 Resource를 MRTG를 이용하여 모니터링하는 방법에 대한 질문을 많이 해주셨는데, 이에 대한 확실한 답변을 드리지 못했던 것이 사실입니다. 그래서 이번에 이우경님(whamsay)이 알려주신 방법과 제가 알고 있는 방법을 같이 소개하고자 합니다. 많이 활용해 보시기 바랍니다.


UCD-SNMP를 설치하여 SUN의 Solaris 모니터링하기
UCD-SNMP 설치
다운받기 : http://net-snmp.sourceforge.net/ 에서 [Download]로 들어가셔서 최신버전으로 다운받으시기 바랍니다. 여기서는 ucd-snmp-4.2.tar.gz를 다운받아서 설치한다.
gzip –d ucd-snmp-4.2.tar.gz
tar -xvf ucd-snmp-4.2.tar
mv ./ucd-snmp*/ /usr/local/ucd-snmp/
cd /usr/local/ucd-snmp
./configure (몇 가지 설정을 물어보는데 기본값을 그대로 사용하면 됩니다.)
make
umask 022
make install


snmpd.conf 파일 및 데몬 실행
cp EXAMPLE.conf /usr/local/share/snmp/snmpd.conf
cd /usr/local/share/snmp
vi snmpd.conf
여기서 ‘com2sec’와 관련된 부분은 community와 관련된 부분으로 수정을 하시던지 아니면 ‘#’으로 아래와 같이 주석처리를 하시면 됩니다.

#com2sec local localhost COMMUNITY

#com2sec mynetwork NETWORK/24 COMMUNITY

/usr/local/sbin/snmpd -> 이렇게 snmp 데몬을 실행을 하시면 되는데, 그전에 기존의 snmp데몬은 다음과 같이 찾으신 후에 kill –9로 죽이시면 됩니다.
ps -ef | grep snmp
/usr/lib/snmp/snmpdx -y -c /etc/snmp/conf


MIB설명
이제 UCD-SNMP가 제공하는 MIB을 이용하여 SUN Solaris에 대한 모니터링이 가능하다.

참조 MIB파일 : /usr/local/ucd-snmp/mibs/UCD-SNMP-MIB.txt

기본 MIB: .iso.org.dod.internet.private.enterprises.ucdavis (.1.3.6.1.4.1.2021)


MEMORY관련 MIB : .1.3.6.1.4.1.2021.4.x.x
‘top’ 명령 결과 : Memory:1024M real, 259M free, 409M swap in use, 3595M swap free

OID MIB 결과값(Kbytes) Description
memTotalSwap .1.3.6.1.4.1.2021.4.3.0 4079424 Swap영역의 전체 크기
memAvailSwap .1.3.6.1.4.1.2021.4.4.0 3680792 사용 가능한 Swap영역
memTotalReal .1.3.6.1.4.1.2021.4.5.0 1026312 물리적 메모리 크기
memAvailReal .1.3.6.1.4.1.2021.4.6.0 293704 사용 가능한 물리적 메모리 크기
memTotalFree .1.3.6.1.4.1.2021.4.11.0 3973968 전체 사용가능한 메모리 크기

위의 top과 결과값은 측정한 시간이 차이가 있으므로 정확하게 일치하지는 않는다.


PROCESSOR관련 MIB : .1.3.6.1.4.1.2021.10.1.3.x
OID MIB 결과값 Description
laLoad-1 .1.3.6.1.4.1.2021.10.1.3.1 0.49 지난 1분 동안의 평균 load
laLoad-5 .1.3.6.1.4.1.2021.10.1.3.2 0.38 지난 5분 동안의 평균 load
laLoad-15 .1.3.6.1.4.1.2021.10.1.3.3 0.41 지난 15분 동안의 평균 load

결과값에 100을 곱하면 백분율이 된다.


DISK관련 MIB : .1.3.6.1.4.1.2021.9.1.x.x
OID MIB 결과값(Kbytes) Description
dskTotal .1.3.6.1.4.1.2021.9.1.6.1 5043518 분할된 디스크의 전체 크기
dskAvail .1.3.6.1.4.1.2021. 9.1.7.1 2440233 사용 가능한 영역
dskUsed .1.3.6.1.4.1.2021. 9.1.8.1 2552850 사용된 영역

위의 MIB을 snmpwalk을 이용해서 확인해 보면, ‘/’로 파티션된 영역에 대해서만 값을 가져옴을 알 수 있다.


sample cfg파일 – CPU Load
CPU사용률에 대한 결과값이 소수점이므로 이를 백분율로 나타내기 위해서 간단히 perl프로그램을 이용하여 작성하였고, 이 작성된 perl 프로그램을 Target에서 실행하도록 하였다.

[주의]실행 가능하도록 다음과 같이 속성을 변경해야 합니다. ‘chmod 755 cpumonitoring.pl’


[perl 프로그램 : cpumonitoring.pl]

mrtg# cat cpumonitoring.pl

------------------------------- cut here --------------------------------

#!/usr/local/bin/perl/perl


system "/usr/local/bin/snmpget 211.39.35.131 public .1.3.6.1.4.1.2021.10.1.3.1 | awk '{print \$3}' > temp";

system "/usr/local/bin/snmpget 211.39.35.131 public .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> ; # 1분 평균 load

$value2 = <fileHandle> ; # 5분 평균 load

chop($value1); # 개행문자 버림

chop($value2); # 개행문자 버림


close( fileHandle );


$one_minute = $value1 * 100 ; # 백분율로 변경

$five_minute = $value2 * 100 ;


print "$one_minute\n$five_minute\n"; # 결과출력


------------------------------- cut here --------------------------------

[cfg파일]


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

# CPU load config for www3

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

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

MaxBytes[cpu]: 100

Title[cpu]: CPU 평균사용률

Ylegend[cpu]: Load Avg

ShortLegend[cpu]: %

Legend1[cpu]: 1 min. CPU load average

Legend2[cpu]: 5 min. CPU load average

LegendI[cpu]:  1min:

LegendO[cpu]:  5min:

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

<TABLE>

<TR><TD>System: </TD><TD>Sun Ultra Spark4</TD></TR>

<TR><TD>Variables: </TD><TD>Green:1분평균, Blue:5분평균</TD></TR>

</TABLE>

#---------------------------------------------------------------


[결과]

CPU 평균 사용률
System: Sun Ultra Spark4
Variables: Green:1분평균, Blue:5분평균



`Daily' Graph (10 Minute Average)


Max 1min: 61.0 % Average 1min: 40.0 % Current 1min: 30.0 %
Max 5min: 44.0 % Average 5min: 37.0 % Current 5min: 33.0 %




sample cfg파일 – MEMORY

############################################
# Avaiable memory config for www3
Target[memory]:.1.3.6.1.4.1.2021.4.4.0&.1.3.6.1.4.1.2021.4.6.0:public@ip
Options[memory]: growright, gauge, absolute, nopercent
MaxBytes[memory]: 2100000
Title[memory]: Memoty사용률 모니터링
Ylegend[memory]: Avaiable memory
ShortLegend[memory]:  
kilo[memory]: 1024
kMG[memory]: ,M,G,T,P
Legend1[memory]: swap free
Legend2[memory]: real free
LegendI[memory]:  swap
LegendO[memory]:  real
PageTop[memory]:<H1>Avaiable memory on bpmaster</H1>
<TABLE>
<TR><TD>System: </TD><TD> Sun Ultra Spark4</TD></TR>
<TR><TD>Totals: </TD><TD>Real = 1024MBytes and Swap = 4096MBytes</TD></TR>
<TR><TD>Variables: </TD><TD>Avaiable memory: Real and Swap</TD></TR>
</TABLE>

#---------------------------------------------------------------


Memory사용률 모니터링
System: Sun Ultra Spark4
Totals: Real = 1024MBytes and Swap = 4096MBytes
Variables: Avaiable memory: Real and Swap



`Daily' Graph (10 Minute Average)


Max swap 989.7 M Average swap 989.2 M Current swap 989.7 M
Max real 38.0 M Average real 29.3 M Current real 27.9 M



위의 내용 외에도 MIB파일을 참조하여 여러 용도로 활용해 보시기 바랍니다.


Linux CMU-SNMP를 설치하여 Linux모니터링하기
위의 UCD-SNMP와 비슷한 서비스를 제공하지만, MIB값이 다르고 Linux계열에서만 설치가 가능합니다.


CMU-SNMP 설치
다운받기 : http://www.gaertner.de/snmp/welcome-3.7last.html 에서 cmu-snmp-linux-3.7-src.tar.gz 파일 받기
tar -xvf cmu-snmp-linux-3.7-src.tar.gz
cd cmu-snmp-linux-3.7
./configure
make
make install
cd ./etc
./installconf -mini <password> (패스워드는 root 패스워드를 넣으면 됩니다.)

데몬실행
/usr/sbin/snmpd -f
확인 : ps aux | grep snmpd


MIB설명
참조 MIB파일 : /usr/lib/mib.txt

기본 MIB: .iso.org.dod.internet.mgmt.mib-2.host (.1.3.6.1.2.1.25)


Storage 관련 MIB – MEMORY와 DISK를 통합 : .1.3.6.1.2.1.25.2.3.1.x.x
‘df –k’ 명령을 이용하여 DISK사용률 확인
Filesystem 1k-blocks Used Available Use% Mounted on

/dev/hda6 1908800 910648 901188 50% /

/dev/hda1 19487 2422 16059 13% /boot

/dev/hdb1 1232176 150120 1019464 13% /home

/dev/hdc1 816976 20 775456 0% /home1


WhatsUp Gold의 Net Tools를 이용한 결과
(What: 1.3.6.1.2.1.25.2.3.1, Get All Subitems선택)

mib-2.25.2.3.1.1 1 2 769 744 833 5633
mib-2.25.2.3.1.3 Mem Swap Disk Disk Disk Disk
mib-2.25.2.3.1.4 1024 1024 1024 1024 1024 1024
mib-2.25.2.3.1.5 127784 102776 19487 1908800 1232176 816976
mib-2.25.2.3.1.6 93140 23752 2422 910648 150120 20

mib-2.25.2.3.1.1 : 인스턴스 값
mib-2.25.2.3.1.3 : Storage 이름
mib-2.25.2.3.1.4 : Storage 단위 크기로써 1024byte.
mib-2.25.2.3.1.5 : Storage 전체 크기
mib-2.25.2.3.1.6 : 사용된 크기

따라서 /dev/hda6의 디스크 사용률을 모니터링하기 위한 mib은 .1.3.6.1.2.1.25.2.3.1.6.774 가 된다.


PROCESSOR관련 MIB : .1.3.6.1.2.1.25.3.3.1.2.x
OID MIB 결과값 Description
hrProcessorLoad .1.3.6.1.2.1.25.3.3.1.2.1 23 지난 1분 동안의 평균 load

UCD-SNMP와는 달리 소수점이 아니라 십진수로 나오므로 이 MIB을 그대로 적용할 수 있다.


Sample cfg파일은 위와 동일하고 Target부분만 수정하면 되므로 생략한다.
결과
Linux서버 Processor Load
`Daily' Graph (5 Minute Average)


Max Usage 23.0 % Average Usage 16.0 % Current Usage 3.0 %
Max Usage 23.0 % Average Usage 16.0 % Current Usage 3.0 %

Linux's Memory 사용률
Total Memory: 128 MBytes



`Daily' Graph (5 Minute Average)



Max Used: 94.6kBytes (74.0%) Average Used: 77.2 kBytes (60.4%) Current Used: 93.8 kBytes (73.4%)
Max Free: 94.6kBytes (74.0%) Average Free: 77.2 kBytes (60.4%) Current Free: 93.8 kBytes (73.4%)


[바로가기 링크] : http://coolx.net/cboard/computer/271



Name
Password
Comment
Copyright © 1999-2017, swindler. All rights reserved. 367,611 visitor ( 1999.1.8-2004.5.26 ), 2,405,771 ( -2017.01.31)

  2HLAB   2HLAB_Blog   RedToolBox   Omil   Omil_Blog