본문 바로가기
네트워크 (LAN,WAN)

RRDTOOL을 이용한 모니터링 툴 CACTI (on FreeBSD)

by 날으는물고기 2009. 2. 24.

RRDTOOL을 이용한 모니터링 툴 CACTI (on FreeBSD)

제  목 : RRDTOOL을 이용한 모니터링 툴 CACTI (on FreeBSD)
작성자 : 정경환 (환건 : WHAN_GUN : http://www.whangun.com)
작성일 : 2005년 9월 6일


디자인이 심심하기 그지없는 MRTG에서 벗어나 좀 더 컬러풀한 RRDTOOL에 끌린 환건. 그래서 RRDTOOL을 이용한 모니터링 툴을 알아보던 중 황보진호(좋은진호)님께서 운영하시는 커피닉스(coffeenix)에서 cacti라는 툴을 알게되었다. 그게 한 6개월인가 8개월 전으로 기억한다.


백문이 불여일견 아니던가? cacti의 모습이 궁금하신 분은 아래의 사이트에 가서 확인하자.
http://www.cacti.net/ (공식 사이트)
http://www.cacti.net/screenshots.php (스크린샷)


여기에 가면 cacti를 쓰고있는 사이트들의 실제 cacti 자료를 볼 수 있다.
http://cacti.net/sites_that_use_cacti.php


웹브라우저를 이용해 공유기 설정을 쉽게 할 수 있듯 cacti도 한 번 설치해 놓으면 웹브라우저를 통해 누구나 쉽게 snmp를 지원하는 장비를 모니터링 할 수 있다. 라우터, 허브, 서버(에 snmp설치 필요) 모두 가능하다.


자 그럼 설치를 시작해보자.


우선 FreeBSD상에서 cacti를 돌리기 위해서는 snmp 툴이 필요하다. ucd-snmp 4.x 와 net-snmp 5.x 둘 중에 하나를 설치해야 한다. (ucd-snmp가 5.x대로 오면서 이름이 net-snmp로 바뀜)


# cd /usr/ports/net-mgmt/net-snmp
# make install clean


설치를 마쳤는가? 설치 끝부분의 안내메세지 대로 /etc/rc.conf에 다음의 내용을 추가한다.

 

snmpd_enable="YES"
snmpd_flags="-a -p /var/run/snmpd.pid"
snmptrapd_enable="YES"
snmptrapd_flags="-a -p /var/run/snmptrapd.pid"


/usr/local/etc/rc.d/ 밑에 snmpd.sh 와 snmptrapd.sh 파일이 생겼을 것이다. 이것들이 서버 시동시에 자동으로 snmp를 띄워주는 역할을 한다.


이제 rrdtool을 설치하러 가자. rrdtool은 1.0.x대 버젼과 1.2.x대 버젼이 있는데 우리는 1.0.x대 버젼을 쓰기로 하자. (1.2.x 도 문제없이 잘 작동하지만 그래프 모양이 이쁘지가 않다 -_-;;)


# cd /usr/ports/net/rrdtool10
# make install clean


끝났다. 다음 cacti를 설치하러 가자. 2005년 9월 6일 현재 최신 버젼은 0.8.6f 이다.


# cd /usr/ports/net/cacti
# make install clean


설치 끝에 우리가 해야할 7단계를 영어로 설명해 놓았다.

 

1: Create the MySQL database:
# mysqladmin --user=root create cacti


2: Create a mysql user/password for cacti:
(change user and/or password if requered)
# echo "GRANT ALL ON cacti.* TO cactiuser at localhost IDENTIFIED BY 'cactiuser'; FLUSH PRIVILEGES;" | mysql


3: Import the default cacti database:
# mysql cacti < /usr/local/share/cacti/cacti.sql


4: Edit share/cacti/include/db-settings.php:
Specify the MySQL user, password and database for your cacti configuration.


5: Add a line to your /etc/crontab file similar to:
*/5 * * * * cacti /usr/local/bin/php /usr/local/share/cacti/poller.php > /dev/null 2>&1


6: Add alias in apache config for the cacti dir:
Alias /cacti "/usr/local/share/cacti/"


7: Open cacti login page in your web browser and login with admin/admin


1: MySQL 데이터베이스 만들기:
# mysqladmin --user=root -p create cacti
(-p를 붙여줘야 root 패스워드를 물어보게 된다)


2: cacti를 위한 MySQL 아이디와 패스워드 만들기
(필요하다면 아이디와 패스워드는 변경해도 좋다)
GRANT ALL ON cacti.* TO cactiuser at localhost IDENTIFIED BY 'cactiuser'; FLUSH PRIVILEGES;
(원본 설명대로 해도되고 mysql -uroot -p 를 실행해서 mysql client 로 들어가서 바로윗줄대로 입력해도 된다)


입력을 다 했으면 다시 쉘로 나와서


3: 기본 cacti 데이터베이스 불러들이기:
# mysql -ucacti -p cacti < /usr/local/share/cacti/cacti.sql


4: /usr/local/share/cacti/include/db-settings.php 수정하기:
MySQL 관련설정을 cacti 데이터베이스 계정에 맞게 설정해준다.


5: /etc/crontab 파일에 아래와 같이 추가해 준다:
*/5 * * * * cacti /usr/local/bin/php /usr/local/share/cacti/poller.php > /dev/null 2>&1


6: 아파치 설정 파일에 cacti 디렉토리 Alias 설정하기:
Alias /cacti "/usr/local/share/cacti/"


7: cacti 로그인 페이지를 웹브라우저에서 불러들여 ID : admin PW admin 으로 로그인 하자:

 


여기까지 마쳤다면 설치가 거의 끝났다고 보아도 무방하다. 이제 /usr/local/share/snmp/snmpd.conf 파일 설정과 웹브라우저에서 cacti 그래프를 설정해 주기만 하면 된다.


/usr/local/share/snmp 디렉토리에 보면 snmpd.conf.example 파일이 하나 있다. snmpd.conf 로 복사해 주고나서 수정을 해 주면 되는데 딱히 어려운 것은 없으니 그냥 보고 해도 될것이나 혹시나 해서 필자의 설정치를 올려놓는다.

 

root@www.k1004.net /usr/local/share/snmp# cat snmpd.conf
##################################################################
#
# snmpd.conf
#
# $Id: snmpd.conf,v 1.6 2004/03/21 02:53:06 matt Exp $
#
##################################################################
# SECTION: System Information Setup
#
#  This section defines some of the information reported in
#  the "system" mib group in the mibII tree.

# syslocation: The [typically physical] location of the system.
#  Note that setting this value here means that when trying to
#  perform an snmp SET operation to the sysLocation.0 variable will make
#  the agent return the "notWritable" error code. IE, including
#  this token in the snmpd.conf file will disable write access to
#  the variable.
#  arguments: location_string

syslocation "Seoul, Korea"

# syscontact: The contact information for the administrator
#  Note that setting this value here means that when trying to
#  perform an snmp SET operation to the sysContact.0 variable will make
#  the agent return the "notWritable" error code. IE, including
#  this token in the snmpd.conf file will disable write access to
#  the variable.
#  arguments: contact_string

syscontact whangun[at}hothothotmail.com

 

##################################################################
# SECTION: Access Control Setup
#
#  This section defines who is allowed to talk to your running
#  snmp agent.

# rwuser: a SNMPv3 read-write user
#  arguments: user [noauth|auth|priv] [restriction_oid]

#rwuser password-goes-here

# rouser: a SNMPv3 read-only user
#  arguments: user [noauth|auth|priv] [restriction_oid]

rouser monitoring noauth

# rocommunity: a SNMPv1/SNMPv2c read-only access community name
#  arguments: community [default|hostname|network/bits] [oid]

rocommunity monitoring localhost
rocommunity monitoring 203.252.160.111

# rwcommunity: a SNMPv1/SNMPv2c read-write access community name
#  arguments: community [default|hostname|network/bits] [oid]

rwcommunity password-goes-here localhost
rwcommunity password-goes-here 203.252.160.111


##################################################################
# SECTION: Monitor Various Aspects of the Running Host
#
#  The following check up on various aspects of a host.

# proc: Check for processes that should be running.
#   proc NAME [MAX=0] [MIN=0]

#   NAME: the name of the process to check for. It must match
#        exactly (ie, http will not find httpd processes).
#   MAX:  the maximum number allowed to be running. Defaults to 0.
#   MIN:  the minimum number to be running. Defaults to 0.

#  The results are reported in the prTable section of the UCD-SNMP-MIB tree
#  Special Case: When the min and max numbers are both 0, it assumes
#  you want a max of infinity and a min of 1.

proc sshd 10 1
proc httpd 10 3
proc imapd 0 1
proc mysqld 1 1

# disk: Check for disk space usage of a partition.
#  The agent can check the amount of available disk space, and make
#  sure it is above a set limit.

#   disk PATH [MIN=100000]

#   PATH: mount path to the disk in question.
#   MIN:  Disks with space below this value will have the Mib's errorFlag set.
#       Can be a raw byte value or a percentage followed by the %
#       symbol. Default value = 100000.

#  The results are reported in the dskTable section of the UCD-SNMP-MIB tree

disk /   20%
disk /usr 10%
disk /var 10%
disk /tmp 10%
disk /home 10%

# load: Check for unreasonable load average values.
#  Watch the load average levels on the machine.

#   load [1MAX=12.0] [5MAX=12.0] [15MAX=12.0]

#   1MAX:  If the 1 minute load average is above this limit at query
#        time, the errorFlag will be set.
#   5MAX:  Similar, but for 5 min average.
#   15MAX: Similar, but for 15 min average.

#  The results are reported in the laTable section of the UCD-SNMP-MIB tree

load 12 12 12

 

##################################################################
# SECTION: Extending the Agent
#
#  You can extend the snmp agent to have it return information
#  that you yourself define.

# exec: run a simple command using exec()
#  arguments: [oid] name /path/to/executable arguments

#exec  WebHits "/usr/local/sbin/logmonster" " -d -r -q"

# sh: run a simple command using system()
#  arguments: [oid] name command arguments
#  similar to exec, but implemented using system() instead of exec()

#  For security reasons, exec should be preferred.

sh  WebHits /usr/local/sbin/logmonster "-d -r -q"
sh  MailDeliv /usr/local/sbin/maillogs "send"
sh  MailSMTP /usr/local/sbin/maillogs "smtp"
sh  MailPOP3 /usr/local/sbin/maillogs "pop3"
sh  MailIMAP /usr/local/sbin/maillogs "imap"
sh  MailRBL  /usr/local/sbin/maillogs "rbl"
sh  MailWeb  /usr/local/sbin/maillogs "webmail"
sh  MailSpam /usr/local/sbin/maillogs "spamassassin"
sh  MailQS   /usr/local/sbin/maillogs "qmailscanner"
sh  MysqlType /usr/local/sbin/mysqlstatus.pl "type"
sh  MysqlQueries /usr/local/sbin/mysqlstatus.pl "queries"
sh     ApacheStats /usr/local/sbin/apastat.pl "localhost"
#sh  MbmonTemp /usr/local/sbin/mbmonstatus.pl "temp"
#sh  MbmonVolt /usr/local/sbin/mbmonstatus.pl "volt"
#sh  MbmonFan /usr/local/sbin/mbmonstatus.pl "fan"


처음 cacti를 사용하면서 한 가지 애먹은게 바로 이 부분이다.


rouser monitoring noauth

# rocommunity: a SNMPv1/SNMPv2c read-only access community name
#  arguments: community [default|hostname|network/bits] [oid]

rocommunity monitoring localhost
rocommunity monitoring 203.252.160.111


monitoring 이라고 되어있는데 cacti 설정에는 monitoring이 기본값이 아니기 때문에 snmp를 못찾는 상황이 발생했었다 -_-;


이제 웹브라우저를 통해 cacti 페이지에 로그인을 하자.
필자의 경우 cacti.whangun.com 으로 설정해 놓았다.


왼쪽에 Configuration 밑에 Settings를 눌러 설정페이지로 간다.
SNMP Utility Version 과 RRDTool Utility Version 부분의 버젼이 맞게 설정되어 있는지 확인한 후에 SNMP Version을 2로 해주고 SNMP Community 부분을 monitoring으로 해준다. 아까 snmpd.conf에서 설정한 바로 그 값이다.


SNMP Port Number 는 기본값이 161이므로 그대로 두고 저장을 누르자.


General 탭은 끝났고 Path 탭에서 경로가 제대로 설정되어 있는지 확인한 후에 왼쪽에 Management 섹션에서 Devices를 눌러보자.


여기서 우측 상단에 Add버튼을 눌러 자신의 호스트를 입력을 하자. 혹시 필요할까 싶어 설정이 완료된 필자의 서버 설정치를 적어둔다.

 

WHANGUN.COM (localhost)
SNMP Information
System: FreeBSD www.k1004.net 4.11-RELEASE-p11 FreeBSD 4.11-RELEASE-p11 #0: Tu i386
Uptime: 315735
Hostname: www.k1004.net


Description : WHANGUN.COM
Hostname : localhost
Host Template : ucd/net SNMP Host
SNMP Community : monitoring
SNMP Version : v2
SNMP Port : 161


Associated Graph Templates 부분과 Associated Data Queries부분은 Add를 눌러 추가를 하면 되는데 필자의 셋팅은 다음과 같다.

 

Associated Graph Templates

Graph Template Name Status
1) ucd/net - CPU Usage Is Being Graphed (Edit)  
2) ucd/net - Memory Usage Is Being Graphed (Edit)  
3) Unix - Load Average Is Being Graphed (Edit)  
4) Unix - Logged in Users Is Being Graphed (Edit)  
5) Unix - Ping Latency Is Being Graphed (Edit)  
6) Unix - Processes Is Being Graphed (Edit) 


Associated Data Queries

Data Query Name Debugging Re-Index Method Status
1) SNMP - Get Processor Information (Verbose Query) Verify All Fields Success [1 Item, 1 Row]   
2) SNMP - Interface Statistics (Verbose Query) Verify All Fields Success [14 Items, 2 Rows]   
3) Unix - Get Mounted Partitions (Verbose Query) Verify All Fields Success [0 Items, 0 Rows]

 

설정을 저장하고 Create 섹션의 New Graphs 로 가자. 여기에서 그래프를 추가해 주면 이제 끝나게 된다. 기본적으로 담겨있는 그래프 외에도 Cacti 사이트에는 여러가지 그래프들의 스크립트가 올라와 있으므로 추가해서 쓸 수도 있음을 기억하자.


다 되었으면 이제 Graph 탭에서 확인해 보자. 왼쪽에 자기 호스트 이름을 눌러주는 센스도 잊지 말 것. (트리를 누르지 않고 바로 그래프가 보이게 하려면 우측 상단에 Setting로 가서 Default View Mode 값을 List View로 설정하고 저장하면 된다)


그래프들이 잘 보인다면 성공! 아니라면 삽질의 길로!
안된다면 Cacti 공식 사이트에 있는 도큐먼트를 참고해 보도록 하자.


http://www.cacti.net/documentation.php
http://www.cacti.net/downloads/docs/html/install_unix.html

728x90

댓글