SNMP(4.2.5) + MRTG(2.9.21) に関するインストールメモ(2002/07/19)
SNMP(Simple Network Management Protocol)は、ネットワークに接続されて機器類を監視するために作成されたプロトコルで、このプロトコルを使用することによってハードウエアが物理的に壊れたとか、ネットワーク回線が不調である等々をソフトウエアから見る(監視)することができる。
RFC1155 : Structure and Identification of Management Information for TCP/IP-based Internets
RFC1157 : A Simple Network Management Protocol (SNMP)
RFC1213 : Management Information Base for Network Management of TCP/IP-based internets: MIB-II
MRTG(Multi Router Traffic Grapher)は、その名の通りルーターを流れるデータ量を起点単位に数値の統計を取りグラフ化してくれるツールです。MRTGは、SNMPマネージャの機能をもっているため、SNMPが組み込まれているハードウエアなりソフトウエアに対しエージェント機能を使用し、数値の統計を取り込む事が可能です。使用例としては、ネットワーク監視、ディスク監視、CPU負荷監視等の用途に使用することができます。
1.既存の snmpマネージャの起動を停止します。設定終了後、トラブル回避のため OSを再起動した方がいいでしょう。
# cd /etc/rc0.d
# mv K07snmpdx _K07snmpdx
# cd /etc/rc1.d
# mv K07snmpdx _K07snmpdx
# cd /etc/rc2.d
# mv K07snmpdx _K07snmpdx
# cd /etc/rc3.d
# mv S76snmpdx _S76snmpdx2.ucd-snmp のインストールを行う。./configure をかけると、問いかけがあります。
% cd /opt/local/src
% wget http://unc.dl.sourceforge.net/sourceforge/net-snmp/ucd-snmp-4.2.5.tar.gz
% gzip -cd ucd-snmp-4.2.5.tar.gz | tar xf -
% cd ucd-snmp-4.2.5
% env CFLAGS=-O3 ./configure
checking if you have run configure before...
************** Configuration Section **************
You are about to be prompted with a series of questions. Answer
them carefully, as they determine how the snmp agent and related
applications are to function.
After the configure script finishes, you can browse the newly
created config.h file for further - less important - parameters to
modify. Be careful if you re-run configure though, since config.h will
be overwritten.
-Press return to continue- ←Enterを押します
disabling above prompt for future runs... yes
checking System Contact Information...
*** System Contact Information:
Describes who should be contacted about the host the agent is
running on. This information is available in the MIB-II tree. This
can also be over-ridden using the "syscontact" syntax in the agent's
configuration files.
System Contact Information (hoge@hoge.co.jp): ←管理者のメールアドレスを入力します
setting System Contact Information to... hoge@hoge.co.jp
checking System Location...
*** System Location:
Describes the location of the system. This information is
available in the MIB-II tree. this can also be over-ridden using the
"syslocation" syntax in the agent's configuration files.
System Location (Unknown): Intel-Solaris8 Server
setting System Location to... Intel-Solaris8 Server
checking Location to write logfile...
*** Logfile location:
Enter the default location for the snmpd agent to dump
information & errors to. If not defined (enter the keyword "none"
at the prompt below) the agent will use stdout and stderr instead.
(Note: This value can be over-ridden using command line options.)
Location to write logfile (/var/log/snmpd.log): ←お好きな場所に♪
setting Location to write logfile to... /var/log/snmpd.log
checking Location to write persistent information...
*** snmpd persistent storage location:
Enter a directory for the snmp library to store persistent
data in the form of a configuration file.
Location to write persistent information (/var/ucd-snmp): ←こちらも (^o^)丿 な
setting Location to write persistent information to... /var/ucd-snmp
3.コンパイルと動作テストをします。
% make
% make test
Summary: 33 / 33 succeeded. ←こう表示されれば ok ♪
make[1]: Leaving directory `/opt/local/src/ucd-snmp-4.2.5/testing'4.インストールをするだす。
% su
# umask 022
# make install5.ucd-snmpエージェントの起動前設定をします。
# cp EXAMPLE.conf /usr/local/share/snmp/snmpd.conf
# vi /usr/local/share/snmp/snmpd.conf
変更点
# sec.name source community
com2sec local localhost PRIVATE
com2sec mynetwork 192.xxx.xxx.xxx/24 HOME
# Second, map the security names into group names:
#group MyRWGroup v1 local
#group MyRWGroup v2c local
#group MyRWGroup usm local
group MyROGroup v1 mynetwork
group MyROGroup v2c mynetwork
group MyROGroup usm mynetwork
# It is also possible to set the sysContact and sysLocation system
# variables through the snmpd.conf file:
syslocation Intel-Solaris8 Unix Server
syscontact Me <hoge@hoge.co.jp>
# Make sure mountd is running
#proc mountd
# Make sure there are no more than 4 ntalkds running, but 0 is ok too.
#proc ntalkd 4
# Make sure at least one sendmail, but less than or equal to 10 are running.
#proc sendmail 10 1
# a simple hello world
#exec echotest /bin/echo hello world
# Check the / partition and make sure it contains at least 10 megs.
disk / 497829
disk /usr/local 25220486.ucd-snmpエージェントの起動をします。
# /usr/local/sbin/snmpd
# ps -ef | grep snmpd
root 26880 26734 0 16:22:25 pts/2 0:00 grep -n snmpd
root 26878 1 0 16:22:18 pts/2 0:00 /usr/local/sbin/snmpd7.動作チェックを行います。下のコマンドを実行し、山の様になんか帰ってくれば ok です。
# snmpwalk -v 1 SNMPエージェントのIPアドレス HOME .1.3.6.1.2.1
8.自動起動するように設定します。
# vi /etc/init.d/ucd-snmp
# chmod +x /etc/init.d/ucd-snmp
# ln -s /etc/init.d/ucd-snmp /etc/rc3.d/S76ucd-snmp
MRTG のコンパイルには、zlib/ libpng / libjpeg / gd が必要です。
gd : http://www.boutell.com/gd/
libpng : http://www.libpng.org/pub/png/
% cd /opt/local/src
% wget ftp://sunsite.sut.ac.jp/pub/sun-info/Solaris/SOURCES/zlib-1.1.4.tar.gz
% gzip -cd zlib-1.1.4.tar.gz | tar xf -
% cd zlib-1.1.4
% env CFLAGS=-O3 ./configure
% make
% make test
% su
# make installlibpng (1.2.1)
% cd /opt/local/src
% wget http://prdownloads.sourceforge.net/libpng/libpng-1.2.1.tar.gz
% tar zxf libpng-1.2.1.tar.gz
% cd libpng-1.2.1
% cp scripts/makefile.solaris ./Makefile
% make
% make test
% su
# make installlibjpeg (6b)
% cd /opt/local/src
% wget ftp://ftp.uu.net/graphics/jpeg/jpegsrc.v6b.tar.gz
% gzip -cd jpegsrc.v6b.tar.gz | tar xf -
% cd jpeg-6b/
% env CFLAGS=-O3 ./configure
% make
% su
# make install
# cp *.h /usr/local/include/gd (1.8.4)
% cd /opt/local/src
% wget http://www.boutell.com/gd/http/gd-1.8.4.tar.gz
% gzip -cd gd-1.8.4.tar.gz | tar xf -
% cd gd-1.8.4
% make
% su
# make install
1.MRTG(2.9.21) のコンパイルを行う。
% cd /opt/local/src
% wget http://people.ee.ethz.ch/~oetiker/webtools/mrtg/pub/mrtg-2.9.21.tar.gz
% gzip -cd mrtg-2.9.21.tar.gz | tar xf -
% cd mrtg-2.9.21
% env CFLAGS=-O3 ./configure --with-gd-lib=/usr/local/lib --with-gd-inc=/usr/local/include
% make
% su
# make install2.MRGT の日本語化を行う。
# cd /opt/local/src/mrtg-2.9.21/translate
# ./mergelocale.pl skeleton.pm0 eucjp.pmd
# ./mergelocale.pl skeleton.pm0 iso2022JP.pmd
# cp locales_mrtg.pm /usr/local/mrtg-2/lib/3.各リソースのデータを格納する場所を作ります。
# mkdir /usr/local/mrtg-2/data
# mkdir /usr/local/mrtg-2/data/traffic
# mkdir /usr/local/mrtg-2/data/cpu
# mkdir /usr/local/mrtg-2/data/memory
# mkdir /usr/local/mrtg-2/data/disk
1.cfg ファイルを作成する。
# /usr/local/mrtg-2/bin/cfgmaker HOME@192.xxx.xxx.xxx > /usr/local/mrtg-2/data/mrtg.cfg
※ /usr/local/mrtg-2/bin/cfgmaker コミュニティ名@SNMPエージェントのIPアドレス2.cfg ファイルを設定する。
# vi /usr/local/mrtg-2/data/mrtg.cfg
WorkDir: /usr/local/mrtg-2/data ←出力先の設定
Language: eucjp ← 日本語化3.実行してみます。下記のコマンドを3回実行します。(2回目までは、ワーニングメッセージが出力されますが差分データが無いだけなので問題ありません)
# /usr/local/mrtg-2/bin/mrtg /usr/local/mrtg-2/data/mrtg.cfg
4.web上から参照できるように、リンクを張ります。
# ln -s /usr/local/mrtg-2/data /opt/local/apache/htdocs/mrtg
# cp /opt/local/src/mrtg-2.9.21/images/* /usr/local/mrtg-2/data5.web上から参照してみましょう。
http://localhost/mrtg/192.xxx.xxx.xxx.html
traffic以外に、CPU使用率/メモリ使用率/ディスク使用率を調べたい場合は、
ucd-snmpとmrtgでサーバ監視 を参考にしながら調整してみてください。
MRTGでディスク使用率を調べたい場合は、SNMPの dskTableディレクティブ(1.3.6.1.4.1.2021.9) の値を参照しグラフ化を行います。
dskTable: dskTableサブツリー(1.3.6.1.4.1.2021.9)
ここでの注意点は /usr/local/share/snmp/snmpd.conf で指定した dskTableディレクティブの指定順番値と監視できるディレクトリの指定があることです。
dskTableディレクティブの指定順番と、1.3.6.1.4.1.2021.9.x は、以下の関係となります。
ディレクトリ指定
dskTableディレクティブの値
disk /
1.3.6.1.4.1.2021.9.1
disk /usr
1.3.6.1.4.1.2021.9.2
disk /export/home
1.3.6.1.4.1.2021.9.3
また監視できるディレクトリの指定は、diskスライス単位でのみ指定することができます。スライス単位とは、df -k で実際に表示されるディスク単位です。スライス=論理ディレクトリ名以下は、SNMPで監視することはできません(指定しても無視されます)。
実際に /usr/local/share/snmp/snmpd.conf を編集したあと、下記のコマンドを実行し dskTableディレクティブが正しく認識されているかどうか確認することができます。
% snmpwalk SNMPエージェントのIPアドレス HOME dskTable
enterprises.ucdavis.dskTable.dskEntry.dskIndex.1 = 1
enterprises.ucdavis.dskTable.dskEntry.dskIndex.2 = 2
enterprises.ucdavis.dskTable.dskEntry.dskIndex.3 = 3
enterprises.ucdavis.dskTable.dskEntry.dskPath.1 = /
enterprises.ucdavis.dskTable.dskEntry.dskPath.2 = /usr
enterprises.ucdavis.dskTable.dskEntry.dskPath.3 = /export/home
enterprises.ucdavis.dskTable.dskEntry.dskDevice.1 = /dev/dsk/c0d0s0
enterprises.ucdavis.dskTable.dskEntry.dskDevice.2 = /dev/dsk/c0d0s6
enterprises.ucdavis.dskTable.dskEntry.dskDevice.3 = /dev/dsk/c0d0s7
/home2 と /tmp を監視するスクリプト作成の手順です。
1.cfg ファイルを作成する。
# /usr/local/mrtg-2/bin/cfgmaker HOME@192.xxx.xxx.xxx > /usr/local/mrtg-2/data/disk/mrtg.cfg
2.cfg ファイルを設定する。
# vi /usr/local/mrtg-2/data/disk/mrtg.cfg
# for UNIX
# WorkDir: /home/http/mrtg
WorkDir: /usr/local/mrtg-2/data/disk
Interval: 5
Refresh: 300
WriteExpires: Yes
Language: eucjp
Options[_]:growright
Target[192.xxx.xxx.xxx_disk]: .1.3.6.1.4.1.2021.9.1.9.3&.1.3.6.1.4.1.2021.9.1.9.6:HOME@192.xxx.xxx.xxx
Options[192.xxx.xxx.xxx_disk]: gauge,absolute,growright,nopercent
SetEnv[192.xxx.xxx.xxx_disk]: MRTG_INT_IP="192.xxx.xxx.xxx" MRTG_INT_DESCR="iprb0"
MaxBytes[192.xxx.xxx.xxx_disk]: 100
WithPeak[192.xxx.xxx.xxx_disk]: mw
Suppress[192.xxx.xxx.xxx_disk]: y
YLegend[192.xxx.xxx.xxx_disk]: Disk Used (%)
LegendI[192.xxx.xxx.xxx_disk]: /home2
LegendO[192.xxx.xxx.xxx_disk]: /tmp
ShortLegend[192.xxx.xxx.xxx_disk]: %
Unscaled[192.xxx.xxx.xxx_disk]: dwmy
Title[192.xxx.xxx.xxx_disk]: Traffic Analysis for 2 -- hoge
PageTop[192.xxx.xxx.xxx_disk]: <H1>DiskSpace for -- hoge</H1>3.実行してみます。下記のコマンドを3回実行します。(2回目までは、ワーニングメッセージが出力されますが差分データが無いだけなので問題ありません)
# /usr/local/mrtg-2/bin/mrtg /usr/local/mrtg-2/data/disk/mrtg.cfg
4.うまくいったら cron に設定しましょう。
1.cfg ファイルを作成する。
# /usr/local/mrtg-2/bin/cfgmaker HOME@192.xxx.xxx.xxx > /usr/local/mrtg-2/data/cpu/mrtg.cfg
2.cfg ファイルを設定する。
# vi /usr/local/mrtg-2/data/cpu/mrtg.cfg
# for UNIX
# WorkDir: /home/http/mrtg
WorkDir: /usr/local/mrtg-2/data/cpu
Interval: 5
Refresh: 300
WriteExpires: Yes
Language: eucjp
Options[_]:gauge,absolute,growright,nopercent
Target[192.xxx.xxx.xxx_cpu]: .1.3.6.1.4.1.2021.10.1.5.1&.1.3.6.1.4.1.2021.10.1.5.2:HOME@192.xxx.xxx.xxx:
MaxBytes[192.xxx.xxx.xxx_cpu]: 100
WithPeak[192.xxx.xxx.xxx_cpu]: mw
YLegend[192.xxx.xxx.xxx_cpu]: Load Average (%)
LegendI[192.xxx.xxx.xxx_cpu]:
LegendO[192.xxx.xxx.xxx_cpu]:
ShortLegend[192.xxx.xxx.xxx_cpu]: %
Unscaled[192.xxx.xxx.xxx_cpu]: dwmy
Title[192.xxx.xxx.xxx_cpu]: CPU Usage for -- hoge
PageTop[192.xxx.xxx.xxx_cpu]: <H1>CPU Usage for -- hoge</H1>3.実行してみます。下記のコマンドを3回実行します。(2回目までは、ワーニングメッセージが出力されますが差分データが無いだけなので問題ありません)
# /usr/local/mrtg-2/bin/mrtg /usr/local/mrtg-2/data/cpu/mrtg.cfg
4.うまくいったら cron に設定しましょう。
ちょびっとだけ面倒です・・・。メモリに対する実際の使用率は、ディレクティブには存在しないため多少の小技が必要らしいです。
1./usr/local/mrtg-2/bin/memory.sh ファイルを作成する。
# vi /usr/local/mrtg-2/bin/memory.sh
#!/bin/ksh
IP=$1
set -A SYS `/usr/local/bin/snmpwalk -v 1 $IP HOME .1.3.6.1.2.1.1.1`
set -A MTS `/usr/local/bin/snmpwalk -v 1 $IP HOME .1.3.6.1.4.1.2021.4.3.0`
set -A MAS `/usr/local/bin/snmpwalk -v 1 $IP HOME .1.3.6.1.4.1.2021.4.4.0`
set -A MTR `/usr/local/bin/snmpwalk -v 1 $IP HOME .1.3.6.1.4.1.2021.4.5.0`
set -A MAR `/usr/local/bin/snmpwalk -v 1 $IP HOME .1.3.6.1.4.1.2021.4.6.0`
MEMR=`/bin/expr ${MTR[2]} - ${MAR[2]}`
SWAR=`/bin/expr ${MTS[2]} - ${MAS[2]}`
HOST=$SYS[3]
/usr/ucb/echo $MEMR
/usr/ucb/echo $SWAR
/usr/ucb/echo ""
/usr/ucb/echo $HOST
# chmod +x /usr/local/mrtg-2/bin/memory.sh2.cfg ファイルを作成する。
# /usr/local/mrtg-2/bin/cfgmaker HOME@192.xxx.xxx.xxx > /usr/local/mrtg-2/data/cpu/mrtg.cfg
3.cfg ファイルを設定する。
# vi /usr/local/mrtg-2/data/cpu/mrtg.cfg
# for UNIX
# WorkDir: /home/http/mrtg
WorkDir: /usr/local/mrtg-2/data/memory
Interval: 5
Refresh: 300
WriteExpires: Yes
Language: eucjp
Options[_]:gauge,absolute,growright,nopercent
Target[192.xxx.xxx.xxx_mem]: `/usr/local/mrtg-2/bin/memory.sh 192.xxx.xxx.xxx`
MaxBytes[192.xxx.xxx.xxx_mem]: 448848
WithPeak[192.xxx.xxx.xxx_mem]: mw
YLegend[192.xxx.xxx.xxx_mem]: Memory Usage(Bytes)
LegendI[192.xxx.xxx.xxx_mem]: Real Memory
LegendO[192.xxx.xxx.xxx_mem]: Swap Memory
ShortLegend[192.xxx.xxx.xxx_mem]: (Bytes)
Unscaled[192.xxx.xxx.xxx_mem]: dwmy
kilo[192.xxx.xxx.xxx_mem]: 1024
kMG[192.xxx.xxx.xxx_mem]: k,M,G,T,P4.実行してみます。下記のコマンドを3回実行します。(2回目までは、ワーニングメッセージが出力されますが差分データが無いだけなので問題ありません)
# /usr/local/mrtg-2/bin/mrtg /usr/local/mrtg-2/data/memory/mrtg.cfg
5.うまくいったら cron に設定しましょう。
MRTGは、1回実行しただけでは意味を持ちません。定期的(5分間隔とか)に実行しその差異を求める事が重要となってきます。そのため、下記の様に cron に定義しましょう。
# setenv EDITOR vi
# crontab -e
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /usr/local/mrtg-2/bin/mrtg /usr/local/mrtg-2/data/mrtg.cfg
HTMLのインデックスページを生成しましょう。
# /usr/local/mrtg-2/bin/indexmaker --prefix=cpu/ cpu/mrtg.cfg > index.html
# /usr/local/mrtg-2/bin/indexmaker --prefix=disk/ disk/mrtg.cfg >> index.html
# /usr/local/mrtg-2/bin/indexmaker --prefix=memory/ memory/mrtg.cfg >> index.html
# /usr/local/mrtg-2/bin/indexmaker mrtg.cfg >> index.htmlそれぞれの設定ファイル。
traffic.cfg ネットワーク転送量の監視
cpu.cfg CPU負荷率の監視
memory.cfg メモリ使用量の監視
disk.cfg ディスク使用率の監視