본문 바로가기

Linux

MRTG on CentOS

yum install gcc* perl* gd* libpng* zlib* -y

cd /usr/local/src

wget http://oss.oetiker.ch/mrtg/pub/mrtg-2.17.4.tar.gz

tar xvfz mrtg-2.17.4.tar.gz

cd mrtg-2.17.4

./configure  --prefix=/usr/local/mrtg-2       \

             --with-gd=/usr/local/src/gd      \

             --with-z=/usr/local/src/zlib     \

             --with-png=/usr/local/src/libpng

make && make install


4. MRTG 설정

1) 웹설정 (<Directory> 설정)


adduser mrtg

mkdir /home/mrtg/public_html

mkdir /home/mrtg/public_html/localhost

mkdir /home/mrtg/conf

chmod 755 /home/mrtg

chown mrtg.mrtg /home/mrtg


vi /etc/httpd/conf/httpd.conf

<IfModule mod_userdir.c>

# UserDir disabled

UserDir public_html

</IfModule>

<Directory /home/*/public_html>

    AllowOverride FileInfo AuthConfig Limit

    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec

    <Limit GET POST OPTIONS>

        Order allow,deny

        Allow from all

    </Limit>

    <LimitExcept GET POST OPTIONS>

        Order deny,allow

        Deny from all

    </LimitExcept>

</Directory>



2) cfgmaker

(모니터링할 대상항목의 Config 파일을 생성하는 작업 입니다.)


cd /usr/local/mrtg-2/bin


./cfgmaker --global 'WorkDir: /home/mrtg/public_html/localhost'  \

          --global 'Options[_]: bits,growright' \

          --output /home/mrtg/conf/mrtg.cfg    \

           public@192.168.99.1



3) 모니터링 Config 수정

(/home/mrtg/cfg/mrtg.cfg 하단부에 추가 합니다.)

vi /home/mrtg/conf/mrtg.cfg

### CPU Load Average ###

Target[cpu]: .1.3.6.1.4.1.2021.10.1.5.1&.1.3.6.1.4.1.2021.10.1.5.2:public@192.168.99.1

MaxBytes[cpu]: 2000

#Unscaled[cpu]: dwmy

Options[cpu]: integer, gauge,withzeroes, growright, noinfo, nopercent

YLegend[cpu]: CPU Load Average

ShortLegend[cpu]: (%)

LegendI[cpu]: Aver 1/minite

LegendO[cpu]: Aver 5/min

Legend1[cpu]: Aver 1/minite

Legend2[cpu]: Aver 5/min

Title[cpu]: CPU Load

PageTop[cpu]: </p><h1>CPU Load Average</h1>


### Rate of CPU use ###

Target[cpu_use]: .1.3.6.1.4.1.2021.11.50.0&.1.3.6.1.4.1.2021.11.52.0:public@192.168.99.1

MaxBytes[cpu_use]: 100

Options[cpu_use]: growright, noinfo, nopercent

YLegend[cpu_use]: CPU usage(%)

ShortLegend[cpu_use]: (%)

LegendI[cpu_use]: User

LegendO[cpu_use]: System

Legend1[cpu_use]: CPU usage(User)(%)

Legend2[cpu_use]: CPU usage(System)(%)

Title[cpu_use]: Rate of CPU use

PageTop[cpu_use]: <h1>Rate of CPU use</h1>


### Memory Free ###

Target[mem]: .1.3.6.1.4.1.2021.4.6.0&.1.3.6.1.4.1.2021.4.4.0:public@192.168.99.1

MaxBytes1[mem]: 7513968

MaxBytes2[mem]: 7513968

Unscaled[mem]: dwmy

Options[mem]: gauge, growright, noinfo

YLegend[mem]: Mem Free(Bytes)

ShortLegend[mem]: Bytes

kilo[mem]: 1024

kMG[mem]: k,M,G,T,P

LegendI[mem]: Real

LegendO[mem]: Swap

Legend1[mem]: RAM [MBytes]

Legend2[mem]: Swap Memory [MBytes]

Title[mem]: Memory Free

PageTop[mem]: <h1>Memory Free</h1>



4) indexmaker 및 mrtg 쿼리



cd /usr/local/mrtg-2/bin


./indexmaker --title "Localhost" /home/mrtg/conf/mrtg.cfg > \

/home/mrtg/public_html/localhost/index.html


env LANG=C /usr/local/mrtg-2/bin/mrtg /home/mrtg/conf/mrtg.cfg



5. 웹사이트 및 crontab 적용

1) 리다이렉션 페이지 생성


cat > /home/mrtg/public_html/localhost/index.html

<meta http-equiv="refresh" content="1;url=./localhost/index.html">




2) 모니터링 스크립트 작성 및 crontab 등록

[root@localhost bin]# mkdir /script

[root@localhost bin]# cat > /script/mrtg.sh

#!/bin/bash

env LANG=C /usr/local/mrtg-2/bin/mrtg /home/mrtg/conf/mrtg.cfg



crontab -e

*/1 * * * * /scripts/mrtg.sh