작은숲:위키노트/MRTG
MRTG(Multi Router Traffic Grapher). CentOS 6.5에서 MRTG 설치와 설정 방법.
설치
# yum install net-snmp net-snmp-utils mrtg
...
Installed:
mrtg.x86_64 0:2.16.2-7.el6 net-snmp.x86_64 1:5.5-54.el6_7.1
net-snmp-utils.x86_64 1:5.5-54.el6_7.1
Dependency Installed:
gd.x86_64 0:2.0.35-11.el6 libXpm.x86_64 0:3.5.10-2.el6
lm_sensors-libs.x86_64 0:3.1.1-17.el6 mrtg-libs.x86_64 0:2.16.2-7.el6
net-snmp-libs.x86_64 1:5.5-54.el6_7.1 perl-IO-Socket-INET6.noarch 0:2.56-4.el6
perl-SNMP_Session.noarch 0:1.12-4.el6 perl-Socket6.x86_64 0:0.23-4.el6
SNMP 설정
/etc/snmp/snmpd.conf 수정.
# 41번째 줄: 주석 처리
#com2sec notConfigUser default public
# 74, 75번째 줄: 주석 해제
# 대문자로 되어 있는 NETWORK와 COMMUNITY 부분을 자신의 IP 주소와 적당한 이름으로 대체.
# 단 COMMUNITY 이름으로 이미 정의되어 있는 private와 public은 쓸 수 없다.
com2sec local localhost mooo
com2sec mynetwork 182.0.0.94/24 mooo
# 78, 79번째 줄: 주석 해제
group MyRWGroup any local
group MyROGroup any mynetwork
# 85번째 줄: 주석 해제
view all included .1 80
# 93, 94번째 줄: 주석 해제
access MyROGroup "" any noauth 0 all none none
access MyRWGroup "" any noauth 0 all all all
# 162, 163번째 줄: 적당한 내용으로 수정
syslocation Local
syscontact Root <root@localhost>
# 215번째 줄: 추가
# httpd와 mysqld의 프로세스 수를 확인하고자 할 때 추가.
proc httpd
proc mysqld
# 290번째 줄: 추가
# httpd와 mysqld의 세션 수를 확인하고자 할 때 추가.
exec httpd_session /etc/snmp/httpd_session.sh
exec mysqld_session /etc/snmp/mysqld_session.sh
# 329번째 줄: 주석 해제
# 루트 디렉토리의 디스크 용량을 확인하고자 할 때 주석 해제.
disk / 10000
# 358번째 줄: 주석 해제
# 시스템 로드를 확인하고자 할 때 주석 해제.
load 12 12 12
/etc/snmp/httpd_session.sh 추가.
#!/bin/sh
netstat -an | grep :80 | grep -v "0.0.0.0" | wc -l
/etc/snmp/mysqld_session.sh 추가.
#!/bin/sh
netstat -an | grep mysql.sock | wc -l
/etc/snmp/httpd_session.sh과 /etc/snmp/mysqld_session.sh의 권한 설정.
# chmod 755 /etc/snmp/httpd_session.sh /etc/snmp/mysqld_session.sh
SNMP 데몬 실행 및 서비스 등록
# /etc/rc.d/init.d/snmpd start
Starting snmpd: [ OK ]
# chkconfig snmpd on
SNMP가 정상적으로 동작하는지 확인.
# snmpwalk -v2c -c mooo localhost system
SNMPv2-MIB::sysDescr.0 = STRING: Linux ...
SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (8526) 0:01:25.26
...
# snmpwalk -v2c -c mooo localhost systemStat
...
UCD-SNMP-MIB::ssCpuUser.0 = INTEGER: 0
UCD-SNMP-MIB::ssCpuSystem.0 = INTEGER: 0
UCD-SNMP-MIB::ssCpuIdle.0 = INTEGER: 99
...
# snmpwalk -v2c -c mooo localhost memory
...
UCD-SNMP-MIB::memTotalReal.0 = INTEGER: 7994276 kB
UCD-SNMP-MIB::memAvailReal.0 = INTEGER: 358748 kB
...
# snmpwalk -v2c -c mooo localhost .1.3.6.1.4.1.2021.2.1.5
UCD-SNMP-MIB::prCount.1 = INTEGER: 6
UCD-SNMP-MIB::prCount.2 = INTEGER: 1
# snmpwalk -v2c -c mooo localhost .1.3.6.1.4.1.2021.8.1.101
UCD-SNMP-MIB::extOutput.1 = STRING: 39
UCD-SNMP-MIB::extOutput.2 = STRING: 1
# snmpwalk -v 1 localhost -c mooo .1.3.6.1.4.1.2021.9
UCD-SNMP-MIB::dskIndex.1 = INTEGER: 1
UCD-SNMP-MIB::dskPath.1 = STRING: /
UCD-SNMP-MIB::dskDevice.1 = STRING: /dev/sda3
...
# snmpwalk -v 1 localhost -c mooo .1.3.6.1.4.1.2021.10
UCD-SNMP-MIB::laIndex.1 = INTEGER: 1
UCD-SNMP-MIB::laIndex.2 = INTEGER: 2
UCD-SNMP-MIB::laIndex.3 = INTEGER: 3
...
snmpwalk -v2c -c mooo localhost system 등에서 mooo는 /etc/snmp/snmpd.conf에서 등록한 `COMMUNITY` 이름으로 대체해야 한다.
MRTG 설정
cfgmaker로 기본 설정을 만든다.
# cfgmaker --global 'WorkDir: /var/www/mrtg/' --global 'Options[_]: growright, bits' -output /etc/mrtg/mrtg.cfg mooo@localhost
이렇게 만들어진 /etc/mrtg/mrtg.cfg로 구동된 MRTG는 입출력 트래픽의 그래프를 만들어낸다. 그 외의 다른 정보들을 추가하기 위해 /etc/mrtg/mrtg.cfg의 마지막에 아래 내용을 추가한다.
LoadMIBs: /usr/share/snmp/mibs/UCD-SNMP-MIB.txt
### load average
Target[red_load]: .1.3.6.1.4.1.2021.10.1.3.1&.1.3.6.1.4.1.2021.10.1.3.2:mooo@localhost * 100
WithPeak[red_load]: dwmy
MaxBytes[red_load]: 10000
Title[red_load]: Load Average -- red
Options[red_load]: gauge, integer, nopercent, growright
YLegend[red_load]: Load Average
LegendI[red_load]: 1 min
LegendO[red_load]: 5 min
Legend1[red_load]: Load average for 1 Min
Legend2[red_load]: Load average for 5 Min
Legend3[red_load]: Max load average for 1 Min
Legend4[red_load]: Max Load average for 5 Min
ShortLegend[red_load]: %
YTicsFactor[red_load]: 0.01
PageTop[red_load]: <h1>Load Average -- red</h1>
### disk usage
Target[red_disk]: .1.3.6.1.4.1.2021.9.1.6.1&.1.3.6.1.4.1.2021.9.1.8.1:mooo@localhost
MaxBytes[red_disk]: 106324048
Title[red_disk]: Disk Usage -- red
kilo[red_disk]: 1024
Options[red_disk]: gauge, growright
YLegend[red_disk]: Disk Usage
LegendI[red_disk]: / Total
LegendO[red_disk]: / Use
Legend1[red_disk]: / Disk Total Size
Legend2[red_disk]: / Disk Free Size
ShortLegend[red_disk]: B
kMG[red_disk]: K,M,G,T,P
PageTop[red_disk]: <h1>Disk Usage -- red</h1>
### memory usage
Target[red_mem]: memTotalReal.0&memAvailReal.0:mooo@localhost
MaxBytes[red_mem]: 7994276
Title[red_mem]: Memory Usage -- red
kilo[red_mem]: 1024
Options[red_mem]: growright, gauge, nopercent
YLegend[red_mem]: Memory Usage
LegendI[red_mem]: Total
LegendO[red_mem]: Free
Legend1[red_mem]: Total Memory Size
Legend2[red_mem]: Free Memory Size
ShortLegend[red_mem]: B
PageTop[red_mem]: <H1>Memory Usage -- red</H1>
### httpd status
Target[red_httpd]: prCount.1&extOutput.1:mooo@localhost
WithPeak[red_httpd]: dwmy
MaxBytes[red_httpd]: 1000
Title[red_httpd]: Httpd Status -- red
Options[red_httpd]: gauge, integer, nopercent, growright
YLegend[red_httpd]: Httpd Status
LegendI[red_httpd]: Processes
LegendO[red_httpd]: Sessions
Legend1[red_httpd]: Number of Httpd Processes
Legend2[red_httpd]: Number of Httpd Sessions
Legend3[red_httpd]: Max Number of Httpd Processes
Legend4[red_httpd]: Max Number of Httpd Sessions
ShortLegend[red_httpd]: n
PageTop[red_httpd]: <H1>Httpd Status -- red</H1>
### mysqld status
Target[red_mysqld]: prCount.2&extOutput.2:mooo@localhost
WithPeak[red_mysqld]: dwmy
MaxBytes[red_mysqld]: 1000
Title[red_mysqld]: Mysqld Status -- red
Options[red_mysqld]: gauge, integer, nopercent, growright
YLegend[red_mysqld]: Mysqld Status
LegendI[red_mysqld]: Processes
LegendO[red_mysqld]: Sessions
Legend1[red_mysqld]: Number of Mysqld Processes
Legend2[red_mysqld]: Number of Mysqld Sessions
Legend3[red_mysqld]: Max Number of Mysqld Processes
Legend4[red_mysqld]: Max Number of Mysqld Sessions
ShortLegend[red_mysqld]: n
PageTop[red_mysqld]: <H1>Mysqld Status -- red</H1>
mrtg.cfg에서 Target[red_load]과 같은 지시자의 대괄호 안에 있는 문자열이 각 항목을 구분한다. 그리고 이 문자열은 HTML 파일과 그래프 이미지 파일의 이름으로 사용된다.
수정 후 mrtg가 제대로 설정 파일을 읽고 동작할 수 있도록 아래와 같이 mrtg를 세 번 정도 실행해준다. 아래의 경고 메시지는 mrtg를 3번 정도 실행하면 더 이상 나오지 않는다.
# for (( i=1 ; i <= 3 ; i++ )); do env LANG=C mrtg /etc/mrtg/mrtg.cfg; done
2016-01-25 19:49:51, Rateup WARNING: /usr/bin/rateup could not read the primary log file for localhost_eth0
2016-01-25 19:49:51, Rateup WARNING: /usr/bin/rateup The backup log file for localhost_eth0 was invalid as well
2016-01-25 19:49:51, Rateup WARNING: /usr/bin/rateup Can't remove localhost_eth0.old updating log file
2016-01-25 19:49:51, Rateup WARNING: /usr/bin/rateup Can't rename localhost_eth0.log to localhost_eth0.old updating log file
2016-01-25 19:49:52, Rateup WARNING: /usr/bin/rateup Can't remove localhost_eth0.old updating log file
웹에서 접근할 수 있도록 인덱스 파일을 만든다. 이후 업데이트는 cron에 등록되어 있어 자동으로 실행된다.
# indexmaker --columns=2 /etc/mrtg/mrtg.cfg > /var/www/mrtg/index.html
# cat /etc/cron.d/mrtg
*/5 * * * * root LANG=C LC_ALL=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg --lock-file /var/lock/mrtg/mrtg_l --confcache-file /var/lib/mrtg/mrtg.ok
아파치 설정
/etc/httpd/conf.d/mrtg.conf 파일을 수정해 접근을 허용할 IP 주소를 등록한다.
## This configuration file maps the mrtg output (generated daily)
# into the URL space. By default these results are only accessible
# from the local host.
#Alias /mrtg /var/www/mrtg
<Location /mrtg>
Order deny,allow
Deny from all
Allow from 127.0.0.1 182.0.0.94/24
Allow from ::1
# Allow from .example.com
</Location>
만약 아파치를 수동으로 설치한 것이라면 /usr/local/apache/conf/httpd.conf 파일 마지막에 아래 내용을 추가한다.
Include /etc/httpd/conf.d/mrtg.conf
이후 아파치를 재기동한 후 아파치 설정에서 Alias로 지정한 MRTG 페이지에 접속해서 확인한다.
참고
- (영어) MRTG 2.17.4 configuration reference
- (영어) Graphing MySQL performance statistics with MRTG <archiveis>xCrqx</archiveis>
- Debian에서 SNMP와 MRTG를 통한 서버 모니터링하기
- MRTG : Install <archiveis>6CU7r</archiveis>
- MRTG 설정 파일의 옵션 항목들에 대한 설명 <archiveis>Cis7R</archiveis>
- Getting Started With MRTG on CentOS 5
- 리눅스로 MRTG 트래픽 분석 서버 구축
- CentOS 6.5 MRTG 설치
- MRTG 설치하기
- MRTG를 이용한 시스템 자원 모니터링(Debian 5.0)
- MRTG에서 네트워크 및 CPU, 메모리 점유율 기록하기
- SNMP를 이용한 MRTG <archiveis>Yt03o</archiveis>
- SNMP로 시스템 모니터링 툴 만들기 <archiveis>9e7HM</archiveis>
- MRTG 팁! 그래프 반전 시키기와 합치기 <archiveis>JthKY</archiveis>
| 배포판 | |
|---|---|
| 서버 프로그램 | |
| 시스템 도구 | |
| 시스템 보안 | |
| 시스템 설정 | |
| HOWTO 문서 | |
| 사용자 설정 | |
| 활용 | |
| 명령어 | |