본문으로 바로가기

MRTG(Multi Router Traffic Grapher) 사용법

category IT/Useful Program 2017. 7. 17. 22:37

 

SNMP 기반 모니터링

cfg : index 만드는 기본이 된다.

index : 페이지에 표시되는 html파일이며 5분마다 mrtg 통해 갱신된다.

mrtg : cfg파일을 이용해 index 갱신한다.

indexmaker : cfg파일을 이용 처음에 index파일 생성

cfgmaker : snmp 이용해 cfg파일 생성

 

RPM 설치 :

yum -y install net-snmp* mrtg* freetype-devel gd-devel libjpeg-devel libpng-devel

yum -y install httpd

 

서버를 보기 좋게 나누기 위해 디렉터리를 나눈다

[root@localhost mrtg]# mkdir web storage mobile private total

 

cfg파일 생성

[root@localhost mrtg]# cfgmaker --global 'WorkDir: /var/www/test/mrtg/storage' --global 'Language: korean' --global 'Options[_]: bits,growright' -output /var/www/mrtg/test/cfg/test.cfg 'test'@10.0.0.10:::::2

WorkDir : index파일과 맞춤 png,jpg 생성 경로

output : cfg파일이 생성될 경로

snmp string 입력시 특수문자있을때를 위해  '' 묶으면 :::::2 64bit사용을 위함

conf 파일 옵션

Target[(png, jpg파일 )] : 12:mobile_7@10.0.0.11:::::2 + 13:mobile_7@10.0.0.12:::::2 (연산 가능)

옵션들 그냥 넣으니까 제대로 안그려짐 트래픽 많은애 내용 붙여넣으면 ..

 

index파일 생성 (cfg파일 변경 index새로 생성해야 )

[root@locahost mrtg]# indexmaker --title "Storage Traffic Page" --output /var/www/mrtg/test/storage/index.html /var/www/mrtg/test/cfg/test.cfg /ex/example.cfg

뒤에 example.cfg와 같이 여러 개의 cfg파일을 합쳐서 만들기 가능

total index --columns=1 추가

env LANG=C /usr/bin/mrtg /var/www/mrtg/test/cfg/test_total.cfg

 

그래프 갱신을 위한 sh, cron  설정

#!/bin/sh

 

env LANG=C /usr/bin/mrtg /var/www/mrtg/cfg/test.cfg

 

*/5 * * * *  /var/www/mrtg/mrtg.sh

 

indexmaker 변경

default options : 기본 옵션 변경 가능

print page end : 바닥에 추가할 내용

new table column if necessary : 바꾸기를 어떤 경우에 할지

 

print page end

 

    $index .= <<ECHO;

<td></td>

</tr>

</TABLE>

ECHO

 

   $index .= <<ECHO if (defined $$opt{pageend});

$$opt{pageend}

ECHO

 

   $index .= <<ECHO if (!$$opt{nolegend});

<BR>

<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0>

  <TR>

        <A HREF="../storage">STORAGE</A></TD> &nbsp;

  <TR>

        <A HREF="../web">WEB</A></TD> &nbsp;

  <TR>

        <A HREF="../mobile">MOBILE</A></TD> &nbsp;

  <TR>

        <A HREF="../private">PRIVATE</A></TD> &nbsp;

  <TR>

        <A HREF="../etc">ETC</A></TD> &nbsp;

</TR>

</TABLE>

ECHO

        $index .= <<ECHO;

</BODY>

</HTML>

ECHO

 

html코드 삽입 가능