NET-SNMPとMRTGの実験
Modified: 27 July 2004
NET-SNMPのダウンロード
"yum"コマンドで、"net-snmp" のダウンロードとインストールを行います。
# yum install -y net-snmp Unable to find pid Gathering header information file(s) from server(s) Server: Fedora Core 2 - i386 - Base Server: Fedora Core 2 - i386 - Released Updates Finding updated packages Downloading needed headers Cannot find a package matching -y net-snmp is installed and is the latest version. No actions to take # rpm -q net-snmp net-snmp-5.1.1-2 #"yum"コマンドで、"net-snmp-util" のダウンロードとインストールを行います。
# yum install -y net-snmp-utils Gathering header information file(s) from server(s) Server: Fedora Core 2 - i386 - Base Server: Fedora Core 2 - i386 - Released Updates Finding updated packages Downloading needed headers gnome-applets-1-2.6.2.1-1 100% |=========================| 47 kB 00:00 Cannot find a package matching -y Resolving dependencies # yum install -y net-snmp-utils Gathering header information file(s) from server(s) Server: Fedora Core 2 - i386 - Base Server: Fedora Core 2 - i386 - Released Updates Finding updated packages Downloading needed headers Cannot find a package matching -y Resolving dependencies Dependencies resolved I will do the following: [install: net-snmp-utils 5.1.1-2.i386] Is this ok [y/N]: y Downloading Packages Getting net-snmp-utils-5.1.1-2.i386.rpm net-snmp-utils-5.1.1-2.i3 100% |=========================| 88 kB 05:32 error: rpmts_HdrFromFdno: MD5 digest: BAD Expected(f566ecf79d3c8d0555463860a0d4c 259) != (deb3417f093022b7115678685818fb98) net-snmp-utils-5.1.1-2.i3 100% |=========================| 154 kB 00:59 Running test transaction: Test transaction complete, Success! net-snmp-utils 100 % done 1/1 Installed: net-snmp-utils 5.1.1-2.i386 Transaction(s) Complete # yum install -y net-snmp-utils Gathering header information file(s) from server(s) Server: Fedora Core 2 - i386 - Base Server: Fedora Core 2 - i386 - Released Updates Finding updated packages Downloading needed headers Cannot find a package matching -y net-snmp-utils is installed and is the latest version. No actions to take # rpm -q net-snmp-utils net-snmp-utils-5.1.1-2 #
理由はよくわかりませんが、インストールされなくなるまで、同じコマンドを何度か実行しないといけないようです。
"/etc/snmp/snmp.conf" を作成する
"/etc/snmp/snmp.conf"を、 以下の2行のファイルとして作成します。
rouser guest rocommunity public 127.0.0.1 disk /home 15%
snmpを起動する
# service snmpd start snmpd を起動中: [ OK ] #
再起動時に自動起動するように設定します。
# chkconfig snmpd on
動作テストする
以下のコマンドを実行してみます。
# snmpwalk -v 2c -c public localhost SNMPv2-MIB::sysDescr.0 = STRING: Linux fc2-100 2.6.6-1.435.2.3 #1 Thu Jul 1 08:25:29 EDT 2004 i686 SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10 SNMPv2-MIB::sysUpTime.0 = Timeticks: (16434) 0:02:44.34 SNMPv2-MIB::sysContact.0 = STRING: root@localhost SNMPv2-MIB::sysName.0 = STRING: fc2-100 SNMPv2-MIB::sysLocation.0 = STRING: Unknown SNMPv2-MIB::sysORLastChange.0 = Timeticks: (33) 0:00:00.33 SNMPv2-MIB::sysORID.1 = OID: IF-MIB::ifMIB : HOST-RESOURCES-MIB::hrSWInstalledLastChange.0 = Timeticks: (0) 0:00:00.00 HOST-RESOURCES-MIB::hrSWInstalledLastUpdateTime.0 = Timeticks: (0) 0:00:00.00 Timeout: No Response from localhost #上記のように、ずらずらと情報が読み出せれば、とりあえずOKです。
MRTGのダウンロード
以下のコマンドで、ダウンロードしインストールします。
# yum install -y mrtg Gathering header information file(s) from server(s) Server: Fedora Core 2 - i386 - Base Server: Fedora Core 2 - i386 - Released Updates Finding updated packages Downloading needed headers Cannot find a package matching -y Resolving dependencies Dependencies resolved I will do the following: [install: mrtg 2.10.5-3.i386] Is this ok [y/N]: y Downloading Packages Getting mrtg-2.10.5-3.i386.rpm mrtg-2.10.5-3.i386.rpm 100% |=========================| 1.0 MB 00:05 Running test transaction: Test transaction complete, Success! mrtg 100 % done 1/1 Installed: mrtg 2.10.5-3.i386 Transaction(s) Complete # rpm -q mrtg mrtg-2.10.5-3 #
"/etc/snmp/snmp.conf"を作成
以下の1行を、"/etc/snmp/snmp.conf" で作成します。
"/etc/snmp/snmpd.conf"ではない。
defVersion 2c
"/etc/mrtg/localhost.cfg"を作成
以下の内容で、"/etc/mrtg/localhost.cfg"を作成します。
WorkDir: /var/www/mrtg LoadMIBs: /usr/share/snmp/mibs/UCD-SNMP-MIB.txt # CPU Load Average Target[cpu]: laLoadInt.1&laLoadInt.2:public@localhost MaxBytes[cpu]: 100 Unscaled[cpu]: dwmy Options[cpu]: gauge,nopercent Title[cpu]: CPU Load Average PageTop[cpu]: <H1>CPU Load Average</H1> YLegend[cpu]: loadavg (%) ShortLegend[cpu]: % LegendI[cpu]: 1min LegendO[cpu]: 5min # Memory Usage Target[mem]: memAvailReal.0&memTotalReal.0:public@localhost MaxBytes[mem]: 131072 Unscaled[mem]: dwmy Options[mem]: gauge,nopercent,integer Title[mem]: Memory Usage PageTop[mem]: <H1>Memory Usage</H1> YLegend[mem]: Available (KB) ShortLegend[mem]: KB LegendI[mem]: Available LegendO[mem]: Total # Network Usage Target[eth0]: 2:public@localhost: SetEnv[eth0]: MRTG_INT_IP="192.168.0.100" MRTG_INT_DESCR="eth0" MaxBytes[eth0]: 1250000 Title[eth0]: Traffic for eth0 PageTop[eth0]: <H1>Traffic for eth0</H1>
mrtgを実行する
mrtgを実行してみます。
最初は、エラーが出ますが、だまって3回実行します。3回目にエラーが出なければOKです。
# mrtg /etc/mrtg/localhost.cfg # mrtg /etc/mrtg/localhost.cfg # mrtg /etc/mrtg/localhost.cfg #
mrtgそのものでエラーが出る場合、コマンドの前に、"LANG=C" を付加して実行してみてください。
定期実行させる
刻々と状況の変化を見るために、cron で定期的(5分おきぐらい)に実行させます。
*/5 * * * * /usr/bin/mrtg /etc/mrtg/localhost.cfg
"/etc/httpd/conf.d/mrtg.conf"を編集する
"/etc/httpd/conf.d/mrtg.conf"を編集し、参照もとのPCのIPアドレス(たとえば、"192.168.0.6")を登録します。
# from the local host. # Alias /mrtg /var/www/mrtg <Location /mrtg> Order deny,allow Deny from all Allow from 127.0.0.1 Allow from ::1 Allow from 192.168.0.6 </Location>
CPUの状況を見る
まだ、監視を開始したばかりなので、単なる罫線です。
メモリの状況を見る
これも、監視を開始したばかりなので、ほとんど単なる罫線です。
ネットワークの状況を見る
これも、監視を開始したばかりなので、ほとんど単なる罫線です。