UJP - 技術情報1

Life is fun and easy!

不正IP報告数

Okan Sensor
 
メイン
ログイン
ブログ カテゴリ一覧

MRTGをRedHat ES3.0にインストールする

MRTGをRedHat ES3.0にインストールする


0.改訂履歴

  • 2005.08.16 新規作成
  • 2005.08.22 configureでGDがエラーになった時の例の追加.
  • 2005.10.27 詳細設定内容の追加.
  • 2005.11.11 記述ミスを修正.
  • 2005.12.20 Disk I/Oについて追記.
  • 2006.02.22 ファイル取得のパスが変更になったので修正.
  • 2006.06.28 HDD温度の取得とグラフ化について追記.
  • 2006.10.04 Disk I/O取得シェルについて,わかりやすいように色を付けた.
  • 2006.12.12 デフォルトのグラフオプションの明示化.
  • 2007.11.14 HTTPD監視について追記.

1.はじめに

 このドキュメントでは,RedHat Linuxにて,MRTGのインストール手順を説明する.

 MRTGとは,Multi Router Traffice Grapherの略で,元々はその名の通りネットワーク機器のルータのトラフィックを記録してグラフ化して見る事ができるツールであるが,プログラムの中身はグラフを作成するツールなので,その他のシステムの監視項目をモニタリングし,グラフを作成するという用途に多数用いられている. その適用範囲は,ネットワークトラフィックだけでなくCPU,メモリ,ハードディスク等のリソースや,Java等のプロセス数等をグラフ化する事等もできる.

 データの収集はSNMPを介して行われるので,複数のコンピュータでSNMPエージェントを稼働させ,MRTGを導入したコンピュータにて集中的に収集する事ができたりする. 前提となるSNMPデーモンの設定は,別資料参照のこと.

 このドキュメントのストーリーは,MRTGを入手して,コンパイル&インストールし,自分自身のコンピュータを監視してみるまでの手順の説明となる.

 詳細な設定については「リファレンス」を参照のこと

2.MRTGインストールの環境等の確認

  • MRTGの公式ページは,下記.
  • まずはお決まりの環境確認から.
  • OS,カーネルのバージョンを確認する.
[root@uranos root]# uname -a
Linux uranos 2.4.21-4.EL #1 Fri Oct 3 18:13:58 EDT 2003 i686 i686 i386 GNU/Linux
[root@uranos root]# cat /etc/redhat-release 
Red Hat Enterprise Linux ES release 3 (Taroon)
[root@uranos root]#
  • 必要なパッケージがインストールされているか確認する.
パッケージ 説明
perl
言語
zlib
圧縮ルーチン
gd
画像ライブラリ
libpng
PNG関連ライブラリ
  • rpmコマンドにてインストールを確認する.
[root@uranos root]# rpm -qa| grep zlib
zlib-1.1.4-8.1
zlib-devel-1.1.4-8.1
[root@uranos root]# rpm -qa| grep perl
perl-Filter-1.29-3
perl-HTML-Parser-3.26-17
perl-libxml-enno-1.02-29
perl-DBD-Pg-1.21-2
perl-libxml-perl-0.07-28
perl-Net-DNS-0.31-3.1
perl-5.8.0-88.4
perl-DateManip-5.40-30
perl-URI-1.21-7
perl-XML-Dumper-0.4-25
perl-XML-Twig-3.09-3
perl-SGMLSpm-1.03ii-11
perl-CPAN-1.61-88.4
perl-DBI-1.32-5
perl-Time-HiRes-1.38-3
perl-HTML-Tagset-3.03-28
perl-libwww-perl-5.65-6
perl-XML-Encoding-1.01-23
perl-CGI-2.81-88.4
newt-perl-1.08-4
mod_perl-1.99_09-10.ent
perl-DBD-MySQL-2.1021-3
perl-Digest-SHA1-2.01-15.1
perl-XML-Parser-2.31-15
perl-Digest-HMAC-1.01-11.1
perl-DB_File-1.804-88.4
perl-Parse-Yapp-1.05-30
perl-XML-Grove-0.46alpha-25
[root@uranos root]# rpm -qa| grep gd
sysklogd-1.4.1-12
gdk-pixbuf-devel-0.18.0-8.1
gd-1.8.4-12
gd-devel-1.8.4-12
gdk-pixbuf-0.18.0-8.1
gdbm-devel-1.8.0-20
gdbm-1.8.0-20
gdm-2.4.1.6-2
gdb-5.3.90-0.20030710.40
gdk-pixbuf-gnome-0.18.0-8.1
[root@uranos root]# rpm -qa| grep libpng
libpng10-1.0.13-8
libpng-1.2.2-16
libpng-devel-1.2.2-16
[root@uranos root]# 

3.MRTGのモジュールインストール

[root@uranos root]# mkdir Download
[root@uranos root]# cd Download
[root@uranos Download]#
[root@uranos Download]# wget http://people.ee.ethz.ch/~oetiker/webtools/mrtg/pub/old/
mrtg-2.12.1.tar.gz
--11:01:00--  http://people.ee.ethz.ch/%7Eoetiker/webtools/mrtg/pub/mrtg-2.12.1.tar.gz
           => `mrtg-2.12.1.tar.gz'
Resolving people.ee.ethz.ch... done.
Connecting to people.ee.ethz.ch[129.132.2.203]:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1,134,805 [application/x-tar]

100%[======================================================>] 1,134,805    179.03K/s
    ETA 00:00

11:01:07 (179.03 KB/s) - `mrtg-2.12.1.tar.gz' saved [1134805/1134805]

[root@uranos Download]#
  • アーカイブを展開する.
[root@uranos Download]# gzip -d mrtg-2.12.1.tar.gz 
[root@uranos Download]# tar xf mrtg-2.12.1.tar 
[root@uranos Download]# ls -la
total 4624
drwxr-xr-x    3 root     root         4096 Aug 16 11:02 .
drwxr-x---    5 root     root         4096 Aug 16 10:53 ..
drwxr-xr-x    9 root     root         4096 Aug 16 11:02 mrtg-2.12.1
-rw-r--r--    1 root     root      4710400 May 17 05:46 mrtg-2.12.1.tar
[root@uranos Download]#  
  • 展開されたディレクトリの中身を見る.
[root@uranos Download]# cd mrtg-2.12.1
[root@uranos mrtg-2.12.1]# ls
ANNOUNCE   MANIFEST          README       configure     images         src
CHANGES    Makefile.NetWare  THANKS       configure.in  install-sh     translate
COPYING    Makefile.Win32    bin          contrib       lib
COPYRIGHT  Makefile.in       config.h.in  doc           mkinstalldirs
[root@uranos mrtg-2.12.1]#
  • configureを実行する.
[root@uranos mrtg-2.12.1]# ./configure
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables... 
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking how to run the C preprocessor... gcc -E
checking whether make sets $(MAKE)... yes
checking for a BSD-compatible install... /usr/bin/install -c
checking for perl... /usr/bin/perl
checking for groff... /usr/bin/groff
checking for egrep... grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for inttypes.h... (cached) yes
checking for unsigned long long... yes
checking for long long... yes
checking for strtoll... yes
checking for printf long long format specifier... %lld
checking for pow in -lm... yes
checking for gdImageGif in -lgd... no
checking for gdImagePng in -lgd... yes
checking for gdImagePng_jpg in -lgd... no
checking for gdImagePng_jpg_ft in -lgd... no
checking for gdImageGd in -lgd... yes
checking gd.h usability... yes
checking gd.h presence... yes
checking for gd.h... yes
checking the weather... (cached) it's fine
checking if we can use GCC-specific compiler options... yes
configure: creating ./config.status
config.status: creating Makefile
config.status: creating config.h
ordering CD from http://people.ee.ethz.ch/~oetiker/wish .... just kidding ;-)

----------------------------------------------------------------
Config is DONE!

Type 'make' to compile the software

       ... that wishlist mentioned above does really exist. So if
you feel like showing your appreciation for MRTG, this is the
place to go. I just love CDs and DVDs

                            -- Tobi Oetiker <oetiker@ee.ethz.ch>
----------------------------------------------------------------
[root@uranos mrtg-2.12.1]#  
  • なお,最後に書いてあるメッセージは,「MRTGに感謝するのならCDかDVDを寄付して」と書かれている.
  • 画像ライブラリ関連でエラーが出ているようであるが,おおむね?問題ないようなので,インストールを続ける.
  • もしかして次のようなエラーがでるかもしれない.
[root@jupiter mrtg-2.12.1]# ./configure
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no

〜略〜


checking for long long... yes
checking for strtoll... yes
checking for printf long long format specifier... %lld
checking for pow in -lm... yes
checking for gdImageGif in -lgd... no
checking for gdImagePng in -lgd... no
checking for gdImagePng_jpg in -lgd... no
checking for gdImagePng_jpg_ft in -lgd... no
checking for gdImageGd in -lgd... yes
checking gd.h usability... yes
checking gd.h presence... yes
checking for gd.h... yes

** Ooops, one of many bad things happened:

   a)  You don't have the GD library installed.
       Get it from http://www.boutell.com, compile it and
       use either --with-gd-lib=DIR and --with-gd-inc=DIR to specify
       its location. You might also have to use --with-z-inc,
             --with-z-lib and --with-png-inc, --with-png-lib for gd
             versions 1.6 and higher.  Check config.log for more
       information on the problem.

   b)  You have the GD library installed, but not the gd.h
       header file.  Download the source (see above) and use
       --with-gd-inc=DIR to specify where the file can be found.

   c)  You have the library and the header file installed, but
       you also have a shared GD library in the same directory. 
       Remove the shared library files and/or links (e.g. 
       libgd.so.2.0.0, libgd.so and libgd.so.2).  This is especially
             likely if you're using a recent (post 1.8.4) version of GD
       and didn't configure it with --disable-shared.

   d)  You have gd library installed and also it's headers, but you are
       missing libpng (and headers) or freetype (and headers)
       (mrtg does not use freetype, but if your copy of gd is precompiled
       against it, you have to install it ... 

   Consider following the instructions in doc/mrtg-unix-guide.txt
[root@jupiter mrtg-2.12.1]#
  • この様な時は,GDのライブラリパスを追加してみる.
[root@jupiter mrtg-2.12.1]# ./configure --with-gd-lib=/usr/local/lib/
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables... 
checking for suffix of object files... o
〜略〜
  • configureが成功したら,makeする.
[root@uranos mrtg-2.12.1]# make 
gcc -DGFORM_GD=gdImagePng -g -O2 -Wall -Wpointer-arith -Wcast-align -Wmissing-
declarations -Wnested-externs -Winline -W -DHAVE_CONFIG_H -c ./src/rateup.c -o 
bin/rateup.o
LD_RUN_PATH= gcc bin/rateup.o -o bin/rateup   -Wl,-Bstatic -lgd -lpng -lz -Wl,-Bdynamic
  -lm 
/usr/bin/perl -0777 -p -i~ -e 's@^#!¥s*/¥S*perl@#! /usr/bin/perl@' ./bin/cfgmaker 
./bin/indexmaker ./bin/mrtg
/usr/bin/perl -0777 -p -i~ -e 's@GRAPHFMT="...";@GRAPHFMT="png";@' ./bin/mrtg 
./bin/indexmaker
[root@uranos mrtg-2.12.1]
  • installを実行する.
[root@uranos mrtg-2.12.1]# make install
/bin/sh ./mkinstalldirs /usr/local/mrtg-2/bin
mkdir /usr/local/mrtg-2
mkdir /usr/local/mrtg-2/bin
for x in ./bin/mrtg ./bin/cfgmaker ./bin/indexmaker; do ¥
  /usr/bin/install -c -m 755 $x /usr/local/mrtg-2/bin; done
for x in bin/rateup; do ¥
  /usr/bin/install -c -m 755 $x /usr/local/mrtg-2/bin; done
/bin/sh ./mkinstalldirs /usr/local/mrtg-2/lib/mrtg2/Pod
mkdir /usr/local/mrtg-2/lib
mkdir /usr/local/mrtg-2/lib/mrtg2
mkdir /usr/local/mrtg-2/lib/mrtg2/Pod
for x in ./lib/mrtg2/*.pm; do ¥
  /usr/bin/install -c -m 644 $x /usr/local/mrtg-2/lib/mrtg2; done
for x in ./lib/mrtg2/Pod/*.pm; do ¥
  /usr/bin/install -c -m 644 $x /usr/local/mrtg-2/lib/mrtg2/Pod; done
/bin/sh ./mkinstalldirs /usr/local/mrtg-2/share/mrtg2/icons
mkdir /usr/local/mrtg-2/share
mkdir /usr/local/mrtg-2/share/mrtg2
mkdir /usr/local/mrtg-2/share/mrtg2/icons
for x in ./images/*.gif ./images/*.png; do ¥
  /usr/bin/install -c -m 644 $x /usr/local/mrtg-2/share/mrtg2/icons; done
/bin/sh ./mkinstalldirs /usr/local/mrtg-2/share/doc/mrtg2
mkdir /usr/local/mrtg-2/share/doc
mkdir /usr/local/mrtg-2/share/doc/mrtg2
(cd .; for x in COPYING COPYRIGHT README CHANGES THANKS doc/*.pod 
doc/*.html doc/*.wml doc/*.txt doc/*.png; do ¥
  /usr/bin/install -c -m 644 $x /usr/local/mrtg-2/share/doc/mrtg2; done)
/bin/sh ./mkinstalldirs /usr/local/mrtg-2/man/man1
mkdir /usr/local/mrtg-2/man
mkdir /usr/local/mrtg-2/man/man1
for x in ./doc/*.1; do ¥
  /usr/bin/install -c -m 644 $x /usr/local/mrtg-2/man/man1; done
[root@uranos mrtg-2.12.1]#  
  • インストール完了.
  • /usr/local/mrtg-2以下に配置された事がわかる.
  • 確認してみる.
[root@uranos mrtg-2.12.1]# cd /usr/local/mrtg-2/
[root@uranos mrtg-2]# ls -la
total 24
drwxr-xr-x    6 root     root         4096 Aug 16 11:12 .
drwxr-xr-x   12 root     root         4096 Aug 16 11:12 ..
drwxr-xr-x    2 root     root         4096 Aug 16 11:12 bin
drwxr-xr-x    3 root     root         4096 Aug 16 11:12 lib
drwxr-xr-x    3 root     root         4096 Aug 16 11:12 man
drwxr-xr-x    4 root     root         4096 Aug 16 11:12 share
[root@uranos mrtg-2]# cd bin
[root@uranos bin]# ls -la
total 504
drwxr-xr-x    2 root     root         4096 Aug 16 11:12 .
drwxr-xr-x    6 root     root         4096 Aug 16 11:12 ..
-rwxr-xr-x    1 root     root        95140 Aug 16 11:12 cfgmaker
-rwxr-xr-x    1 root     root        24882 Aug 16 11:12 indexmaker
-rwxr-xr-x    1 root     root        88253 Aug 16 11:12 mrtg
-rwxr-xr-x    1 root     root       275522 Aug 16 11:12 rateup
[root@uranos bin]#  
  • 意外にこじんまり.

4,SNMPエージェントを起動する(監視される側の設定)

  • MRTGは,SNMPによって各マシンのリソース状況を監視する.
  • 監視される側のマシンでは,SNMPデーモンが稼働している必要がある.
  • 今回は,便宜上,MRTGを導入するマシン上で稼働させてみた.
  • まずは,SNMPモジュールがインストールされているか確認する.
[root@uranos mrtg-2]# rpm -qa|grep snmp
net-snmp-5.0.8-11
net-snmp-utils-5.0.8-11
net-snmp-devel-5.0.8-11
[root@uranos mrtg-2]#  
  • SNMPデーモンが起動しているか確認し,無ければデーモンを起動する.
[root@uranos mrtg-2]# ps -ef | grep snmpd
root     18877 17414  0 11:23 pts/0    00:00:00 grep snmpd
[root@uranos mrtg-2]# locate snmpd       
/etc/rc.d/init.d/snmpd
/etc/rc.d/rc0.d/K50snmpd
/etc/rc.d/rc1.d/K50snmpd
/etc/rc.d/rc2.d/K50snmpd
/etc/rc.d/rc3.d/K50snmpd
/etc/rc.d/rc4.d/K50snmpd
/etc/rc.d/rc5.d/K50snmpd
/etc/rc.d/rc6.d/K50snmpd
/etc/logrotate.d/snmpd
/etc/snmp/snmpd.conf
/usr/share/man/man1/snmpdelta.1.gz
/usr/share/man/man1/snmpdf.1.gz
/usr/share/man/man5/snmpd.conf.5.gz
/usr/share/man/man8/snmpd.8.gz
/usr/share/man/ja/man1/snmpdf.1.gz
/usr/share/man/ja/man5/snmpd.conf.5.gz
/usr/share/snmp/snmpconf-data/snmpd-data
/usr/share/snmp/snmpconf-data/snmpd-data/basic_setup
/usr/share/snmp/snmpconf-data/snmpd-data/acl
/usr/share/snmp/snmpconf-data/snmpd-data/snmpconf-config
/usr/share/snmp/snmpconf-data/snmpd-data/extending
/usr/share/snmp/snmpconf-data/snmpd-data/monitor
/usr/share/snmp/snmpconf-data/snmpd-data/operation
/usr/share/snmp/snmpconf-data/snmpd-data/trapsinks
/usr/share/snmp/snmpconf-data/snmpd-data/system
/usr/sbin/snmpd
/usr/bin/snmpdelta
/usr/bin/snmpdf
[root@uranos mrtg-2]# /etc/rc.d/init.d/snmpd start
snmpdを起動中:
[root@uranos mrtg-2]# ps -ef | grep snmpd
root     18921     1  0 11:32 ?        00:00:00 /usr/sbin/snmpd -s -l /dev/null -P
 /var/run/snmpd -a
root     18989 17414  0 11:35 pts/0    00:00:00 grep snmpd
[root@uranos mrtg-2]#  
  • 稼働した.

5.MRTGの設定

  • HTML格納用ディレクトリを作成する.
[root@uranos mrtg-2]# pwd
/usr/local/mrtg-2
[root@uranos mrtg-2]# mkdir data
[root@uranos mrtg-2]# ls -la
total 28
drwxr-xr-x    7 root     root         4096 Aug 16 11:17 .
drwxr-xr-x   12 root     root         4096 Aug 16 11:12 ..
drwxr-xr-x    2 root     root         4096 Aug 16 11:12 bin
drwxr-xr-x    2 root     root         4096 Aug 16 11:17 data
drwxr-xr-x    3 root     root         4096 Aug 16 11:12 lib
drwxr-xr-x    3 root     root         4096 Aug 16 11:12 man
drwxr-xr-x    4 root     root         4096 Aug 16 11:12 share
[root@uranos mrtg-2]#  
  • 作成したディレクトリに,ソースファイル内にあったイメージが格納されたディレクトリを丸ごと複写する.
[root@uranos mrtg-2]# cp -R /root/Download/mrtg-2.12.1/images data/.
[root@uranos mrtg-2]# ls -la data/images 
total 52
drwxr-xr-x    2 root     root         4096 Aug 16 12:22 .
drwxr-xr-x    3 root     root         4096 Aug 16 12:22 ..
-rw-r--r--    1 root     root          350 Aug 16 12:22 favicon.ico
-rw-r--r--    1 root     root          343 Aug 16 12:22 mrtg-l.gif
-rw-r--r--    1 root     root          538 Aug 16 12:22 mrtg-l.png
-rw-r--r--    1 root     root         1144 Aug 16 12:22 mrtg-m.gif
-rw-r--r--    1 root     root          414 Aug 16 12:22 mrtg-m.png
-rw-r--r--    1 root     root         1779 Aug 16 12:22 mrtg-r.gif
-rw-r--r--    1 root     root         1759 Aug 16 12:22 mrtg-r.png
-rw-r--r--    1 root     root         4696 Aug 16 12:22 mrtg-ti.gif
-rw-r--r--    1 root     root         4293 Aug 16 12:22 mrtg-ti.png
[root@uranos mrtg-2]#  
  • cfgmakerコマンドを利用して,設定ファイルを作成する.
  • 文法は,"コミュニティ名@SNMPエージェントのIPアドレス"となるが,ここではコミュニティ名をpublicとしてローカルホストのIPアドレスを指定した.
[root@uranos data]# /usr/local/mrtg-2/bin/cfgmaker local_community@localhost > ¥
>  /usr/local/mrtg-2/data/mrtg.cfg
--base: Get Device Info on local_community@localhost:
--base: Vendor Id: 
--base: Populating confcache
--coca: populate confcache local_community@localhost:
--coca: store in confcache local_community@localhost_ Descr lo --> 1
--coca: store in confcache local_community@localhost_ Descr eth0 --> 2
--coca: store in confcache local_community@localhost_ Descr eth1 --> 3
--coca: store in confcache local_community@localhost_ Type 24 --> 1
--coca: store in confcache local_community@localhost_ Type 6 --> 2
--coca: store in confcache local_community@localhost_ Type 6 --> 3 (duplicate)
--coca: store in confcache local_community@localhost_ Ip 127.0.0.1 --> 1
--coca: store in confcache local_community@localhost_ Ip 192.168.101.200 --> 2
--coca: store in confcache local_community@localhost_ Eth  --> 1
--coca: store in confcache local_community@localhost_ Eth 00-90-ff-20-ab-23 --> 2
--coca: store in confcache local_community@localhost_ Eth 00-50-aa-6b-c3-8f --> 3
--base: Get Interface Info
--base: Walking ifIndex
--base: Walking ifType
--base: Walking ifAdminStatus
--base: Walking ifOperStatus
--base: Walking ifMtu
--base: Walking ifSpeed
[root@uranos data]#  
  • 作成された定義情報を確認する.
[root@uranos mrtg-2]# cat /usr/local/mrtg-2/data/mrtg.cfg
# Created by 
# bin/cfgmaker local_community@uranos


### Global Config Options

#  for UNIX
# WorkDir: /home/http/mrtg

#  or for NT
# WorkDir: c:¥mrtgdata

### Global Defaults

#  to get bits instead of bytes and graphs growing to the right
# Options[_]: growright, bits

EnableIPv6: no

######################################################################
# System: uranos
# Description: Linux uranos 2.4.21-4.EL #1 Fri Oct 3 18:13:58 EDT 2003 i686
# Contact: Root <root@localhost> (configure /etc/snmp/snmp.local.conf)
# Location: JAPAN 
######################################################################


### Interface 1 >> Descr: 'lo' | Name: '' | Ip: '127.0.0.1' | Eth: '' ###
### The following interface is commented out because:
### * it is a Software Loopback interface
# 
# Target[127.0.0.1_1]: 1:local_community@uranos:
# SetEnv[127.0.0.1_1]: MRTG_INT_IP="127.0.0.1" MRTG_INT_DESCR="lo"
# MaxBytes[127.0.0.1_1]: 1250000
# Title[127.0.0.1_1]: Traffic Analysis for 1 -- uranos
# PageTop[127.0.0.1_1]: <h1>Traffic Analysis for 1 -- uranos</h1>
#               <div id="sysdetails">
#                       <table>
#                               <tr>
#                                       <td>System:</td>
#                                       <td>uranos in JAPAN </td>
#                               </tr>
#                               <tr>
#                                       <td>Maintainer:</td>
#                                       <td>Root &lt;root@localhost&gt; (con
figure /etc/snmp/snmp.local.conf)</td>
#                               </tr>
#                               <tr>
#                                       <td>Description:</td>
#                                       <td>lo  </td>
#                               </tr>
#                               <tr>
#                                       <td>ifType:</td>
#                                       <td>softwareLoopback (24)</td>
#                               </tr>
#                               <tr>
#                                       <td>ifName:</td>
#                                       <td></td>
#                               </tr>
#                               <tr>
#                                       <td>Max Speed:</td>
#                                       <td>1250.0 kBytes/s</td>
#                               </tr>
# 
#                               <tr>
#                                       <td>Ip:</td>
#                                       <td>127.0.0.1 (uranos)</td>
#                               </tr>
# 
#                       </table>
#               </div>


### Interface 2 >> Descr: 'eth0' | Name: '' | Ip: '' | Eth: '00-03-25-00
-c8-71' ###

Target[127.0.0.1_2]: 2:local_community@uranos:
SetEnv[127.0.0.1_2]: MRTG_INT_IP="" MRTG_INT_DESCR="eth0"
MaxBytes[127.0.0.1_2]: 12500000
Title[127.0.0.1_2]: Traffic Analysis for 2 -- uranos
PageTop[127.0.0.1_2]: <h1>Traffic Analysis for 2 -- uranos</h1>
                <div id="sysdetails">
                        <table>
                                <tr>
                                        <td>System:</td>
                                        <td>uranos in JAPAN </td>
                                </tr>
                                <tr>
                                        <td>Maintainer:</td>
                                        <td>Root &lt;root@localhost&gt; (con
figure /etc/snmp/snmp.local.conf)</td>
                                </tr>
                                <tr>
                                        <td>Description:</td>
                                        <td>eth0  </td>
                                </tr>
                                <tr>
                                        <td>ifType:</td>
                                        <td>ethernetCsmacd (6)</td>
                                </tr>
                                <tr>
                                        <td>ifName:</td>
                                        <td></td>
                                </tr>
                                <tr>
                                        <td>Max Speed:</td>
                                        <td>12.5 MBytes/s</td>
                                </tr>

                        </table>
                </div>


### Interface 3 >> Descr: '' | Name: '' | Ip: '192.168.107.248' | Eth: '' ###
### The following interface is commented out because:
### * has a speed of  which makes no sense
### * got 'Received SNMP response with error code
###       error status: noSuchName
###       index 1 (OID: 1.3.6.1.2.1.2.2.1.10.3)
###     SNMPv1_Session (remote host: "127.0.0.1" [127.0.0.1].161)
###                       community: "public"
###                      request ID: -1822743436
###                     PDU bufsize: 8000 bytes
###                         timeout: 2s
###                         retries: 5
###                         backoff: 1)' from interface when trying to query
# 
# Target[127.0.0.1_3]: 3:local_community@uranos:
# SetEnv[127.0.0.1_3]: MRTG_INT_IP="192.168.107.248" MRTG_INT_DESCR=""
# MaxBytes[127.0.0.1_3]: 0
# Title[127.0.0.1_3]: Traffic Analysis for 3 -- uranos
# PageTop[127.0.0.1_3]: <h1>Traffic Analysis for 3 -- uranos</h1>
#               <div id="sysdetails">
#                       <table>
#                               <tr>
#                                       <td>System:</td>
#                                       <td>uranos in JAPAN </td>
#                               </tr>
#                               <tr>
#                                       <td>Maintainer:</td>
#                                       <td>Root &lt;root@localhost&gt; (configure
 /etc/snmp/snmp.local.conf)</td>
#                               </tr>
#                               <tr>
#                                       <td>Description:</td>
#                                       <td>  </td>
#                               </tr>
#                               <tr>
#                                       <td>ifType:</td>
#                                       <td> ()</td>
#                               </tr>
#                               <tr>
#                                       <td>ifName:</td>
#                                       <td></td>
#                               </tr>
#                               <tr>
#                                       <td>Max Speed:</td>
#                                       <td>0.0 Bytes/s</td>
#                               </tr>
# 
#                               <tr>
#                                       <td>Ip:</td>
#                                       <td>192.168.107.248
 (mars.ujp.jp)</td>
#                               </tr>
# 
#                       </table>
#               </div>


[root@uranos mrtg-2]#  
  • これで作成された設定ファイルはひな形なので,これから設定する.
  • まずは,WorkDirを設定する.
[root@uranos mrtg-2]# head -10 /usr/local/mrtg-2/data/mrtg.cfg
WorkDir: /usr/local/mrtg-2/data
# Created by 
# bin/cfgmaker local_community@uranos


### Global Config Options

#  for UNIX
# WorkDir: /home/http/mrtg

[root@uranos mrtg-2]#  
  • 日本語設定と,ブラウザでのリフレッシュ時間を設定する.
#  to get bits instead of bytes and graphs growing to the right
# Options[_]: growright, bits

EnableIPv6: no

Language: eucjp
Refresh: 300
  • グラフのオプションを設定する.
#-----------------------------------------------------------------
# Graph Option
#-----------------------------------------------------------------
Options[_]: growright,gauge
  • デフォルトでは,右から左にグラフが流れていくので,それを右側が最新に増えるように設定する.
  • 項目が,[_]となっているのは,デフォルトを意味する.
  • httpdプロセス数について設定する.
  • プロセス数の監視をする為には,snmp.confにproc httpd等の設定を追加して,SNMPDを再起動する必要がある.
#-----------------------------------------------------------------
# httpd Process
#-----------------------------------------------------------------
Options[httpd]: growright,gauge
Target[httpd]: .1.3.6.1.4.1.2021.2.1.5.1&.1.3.6.1.4.1.2021.2.1.4.1:local_c
ommunity@localhost:
ThreshMaxI[httpd]: 20
SetEnv[httpd]: EMAIL="root@localhost"
               URL="http://localhost/httpd.html"
MaxBytes[httpd]: 100
Title[httpd]: Number of httpd
PageTop[httpd]: <H1> Number of httpd</H1>
YLegend[httpd]: Number of httpd
ShortLegend[httpd]: httpd 
LegendI[httpd]:httpd count
LegendO[httpd]:dummy 
Unscaled[httpd]: dwmy
  • ここでは,最大100プロセスとする.
  • httpd.confの設定によって調整する.
  • CPUのロードアベレージを設定する.
#-----------------------------------------------------------------
# CPU Load Average x 100
#-----------------------------------------------------------------
Options[CPUload]: growright,gauge
Target[CPUload]: .1.3.6.1.4.1.2021.10.1.5.1&.1.3.6.1.4.1.2021.10.1.5.3:local_community@localhost:
ThreshMaxI[CPUload]: 100
SetEnv[CPUload]: EMAIL="root@localhost"
            URL="CPUload.html"
MaxBytes[CPUload]: 100
Title[CPUload]: Load Average
PageTop[CPUload]: <H1> Load Average</H1>
YLegend[CPUload]: Load Average
ShortLegend[CPUload]: %
LegendI[CPUload]:1 min
LegendO[CPUload]:15 min
Unscaled[CPUload]: dwmy
  • ここでは1分間平均,15分間平均を取得する.
  • ディスク容量を設定する.
  • まずは,パーティションを調べる.
[root@uranos htdocs]# snmpwalk -v 2c localhost -c local_community .1.3.6.1.4.1.2021.9.1.3
UCD-SNMP-MIB::dskDevice.1 = STRING: /dev/hdc2
UCD-SNMP-MIB::dskDevice.2 = STRING: /dev/hdc5
[root@uranos htdocs]#  
  • /dev/hdc2と/dev/hdc5を取得できる事がわかった.
  • どのパーティションなのかを調べる.
[root@uranos htdocs]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/hdc2              36G   11G   23G  33% /
/dev/hdc1              99M  9.1M   85M  10% /boot
/dev/hdc5             487M   11M  451M   3% /home
none                  250M     0  250M   0% /dev/shm
[root@uranos htdocs]#  
  • ルートパーティションと/homeである事がわかる.
  • 使用率を確認する.
[root@uranos htdocs]# snmpwalk -v 2c localhost -c local_community .1.3.6.1.4.1.2021.9.1.9.1
UCD-SNMP-MIB::dskPercent.1 = INTEGER: 33
[root@uranos htdocs]# snmpwalk -v 2c localhost -c local_community .1.3.6.1.4.1.2021.9.1.9.2
UCD-SNMP-MIB::dskPercent.2 = INTEGER: 2
[root@uranos htdocs]#
  • 前述のdfコマンドと比較してちょっと違うが,誤差の範囲か.
#-----------------------------------------------------------------
# Disk Usage
#-----------------------------------------------------------------
Options[df]: growright,gauge
Target[df]: .1.3.6.1.4.1.2021.9.1.9.1&.1.3.6.1.4.1.2021.9.1.9.2:local_community@localhost:
ThreshMaxI[df]: 80
SetEnv[df]: EMAIL="root@localhost"
            URL="DiskUsage1.html"
MaxBytes[df]: 100
Title[df]: Disk Usage "/" and "/home"
PageTop[df]: <H1>Disk Usage </H1>
YLegend[df]: Disk Usage
ShortLegend[df]: %
LegendI[df]:/
LegendO[df]:/home
Unscaled[df]: dwmy
  • 実メモリとスワップメモリの総容量を調べる.
[root@uranos htdocs]# snmpwalk -v 2c localhost -c local_community .1.3.6.1.4.1.2021.4.5
UCD-SNMP-MIB::memTotalReal.0 = INTEGER: 511928
[root@uranos htdocs]# snmpwalk -v 2c localhost -c local_community .1.3.6.1.4.1.2021.4.3
UCD-SNMP-MIB::memTotalSwap.0 = INTEGER: 1044216
[root@uranos htdocs]#  
  • ここではKB単位になっているので,物理メモリが約500M,スワップ領域が1GBということがわかる.
  • freeコマンドを使っても確認できる.
[root@uranos htdocs]# free
             total       used       free     shared    buffers     cached
Mem:        511928     505308       6620          0       1812      52036
-/+ buffers/cache:     451460      60468
Swap:      1044216     522108     522108
[root@uranos htdocs]#  
  • 調べた物理メモリとスワップメモリ領域を設定する.
#-----------------------------------------------------------------
# Available memory
#     Please 'MaxByte' set your computer swap size.
#-----------------------------------------------------------------
Options[mem]: growright,gauge
Target[mem]: .1.3.6.1.4.1.2021.4.6.0&.1.3.6.1.4.1.2021.4.4.0:local_community@localhost:
ThreshMinO[mem]: 50
SetEnv[mem]: EMAIL="root@localhost"
            URL="memory.html"
MaxBytes1[mem]: 511928
MaxBytes2[mem]: 1044216
Title[mem]: Available Memory ("real" and "swap")
PageTop[mem]: <H1>Available Memory "real" and "swap"</H1>
YLegend[mem]: Available Memory
ShortLegend[mem]: byte
LegendI[mem]:Free Real Memory
LegendO[mem]:Free Swap Memory
kMG[mem]: k,M,G,T,P
Unscaled[mem]: dwmy
  • 設定したこの値が最大値とされ,Unscaledとしているので百分率のグラフとなる.
  • Disk I/Oについては,次の通り.
#-----------------------------------------------------------------
# Disk I/O
# /usr/local/mrtg-2/bin/disk_io.sh
#-----------------------------------------------------------------
Options[disk_io]: growright
Target[disk_io]: `/usr/local/mrtg-2/bin/disk_io.sh`
MaxBytes[disk_io]: 200
Title[disk_io]: Disk I/O
PageTop[disk_io]: <H1>Disk I/O</H1>
YLegend[disk_io]: Disk I/O
ShortLegend[disk_io]: blocks/s
LegendI[disk_io]:Read Block
LegendO[disk_io]:Write Block
  • optionでgrowrightを追記.
  • これは,/proc/statsにてRead/WriteのI/Oブロック数を取得するコマンドを実行している.
  • 取得するコマンドの中身は次の通り.
[root@uranos data]# cat /usr/local/mrtg-2/bin/disk_io.sh
#!/bin/sh

ReadCount=`cat /proc/stat|grep disk_io | tr -d '('|tr -d ')'| tr : ,| cut -f 5 -d','`
WriteCount=`cat /proc/stat|grep disk_io | tr -d '('|tr -d ')'| tr : ,| cut -f 7 -d','`

#echo $ReadCount $WriteCount 0 0 0
echo $ReadCount
echo $WriteCount
echo 0 
echo 0 
[root@uranos data]# chmod ogu+x /usr/local/mrtg-2/bin/disk_io.sh
[root@uranos data]# /usr/local/mrtg-2/bin/disk_io.sh
762004
2655010
0
0
[root@uranos data]#  
  • ハードディスクの温度について取得する設定を行う.
#-----------------------------------------------------------------
# Disk Tempereture
# /usr/local/mrtg-2/bin/HDDtemp.sh
#-----------------------------------------------------------------
Options[disk_temp]: growright,gauge
Target[disk_temp]: `/usr/local/mrtg-2/bin/HDDtemp.sh`
MaxBytes[disk_temp]:100
Title[disk_temp]: Disk Temperature
PageTop[disk_temp]: <H1>Disk Temperature</H1>
YLegend[disk_temp]: Disk temperature
ShortLegend[disk_temp]: C
LegendI[disk_temp]: Celsius
LegendO[disk_temp]: Best
Unscaled[disk_temp]: dwmy
  • 温度を取得するために,次のようなコマンドを作成する.
[root@uranos data]# cat /usr/local/mrtg-2/bin/HDDtemp.sh
#!/bin/bash

export LOG_TEMP=`/usr/sbin/smartctl -a /dev/hda | grep Temperature | cut -c 78-79`

echo $LOG_TEMP
echo 40 
echo 0 
echo 0 
[root@uranos data]# 
[root@uranos data]# chmod ogu+x /usr/local/mrtg-2/bin/HDDtemp.sh
[root@uranos data]# /usr/local/mrtg-2/bin/HDDtemp.sh
67
40
0
0
[root@uranos data]# 
  • MRTGを実行してみる.
[root@uranos mrtg-2]# pwd
/usr/local/mrtg-2
[root@uranos mrtg-2]# cd data
[root@uranos data]# ls -la
total 20
drwxr-xr-x 3 root root 4096 Aug 16 16:03 .
drwxr-xr-x 7 root root 4096 Aug 16 14:28 ..
drwxr-xr-x 2 root root 4096 Aug 16 12:22 images
-rw-r--r-- 1 root root 4216 Aug 16 16:01 mrtg.cfg
-rw-r--r-- 1 root root 0 Aug 16 16:02 mrtg.ok
[root@uranos data]# /usr/local/mrtg-2/bin/mrtg /usr/local/mrtg-2/data/mrtg.cfg
Rateup WARNING: /usr/local/mrtg-2/bin/rateup could not read the primary log file for
 127.0.0.1_2
Rateup WARNING: /usr/local/mrtg-2/bin/rateup The backup log file for 127.0.0.1_2 was
 invalid as well
Rateup WARNING: /usr/local/mrtg-2/bin/rateup Can't remove 127.0.0.1_2.old updating l
og file
Rateup WARNING: /usr/local/mrtg-2/bin/rateup Can't rename 127.0.0.1_2.log to
 127.0.0.1_2.old updating log file
[root@uranos data]# /usr/local/mrtg-2/bin/mrtg /usr/local/mrtg-2/data/mrtg.cfg
Rateup WARNING: /usr/local/mrtg-2/bin/rateup Can't remove 127.0.0.1_2.old updating l
og file
[root@uranos data]# /usr/local/mrtg-2/bin/mrtg /usr/local/mrtg-2/data/mrtg.cfg
[root@uranos data]# ls -la
total 152
drwxr-xr-x 3 root root 4096 Aug 16 16:04 .
drwxr-xr-x 7 root root 4096 Aug 16 14:28 ..
-rw-r--r-- 1 root root 1474 Aug 16 16:04 127.0.0.1_2-day.png
-rw-r--r-- 1 root root 1439 Aug 16 16:04 127.0.0.1_2-month.png
-rw-r--r-- 1 root root 1447 Aug 16 16:04 127.0.0.1_2-week.png
-rw-r--r-- 1 root root 1810 Aug 16 16:04 127.0.0.1_2-year.png
-rw-r--r-- 1 root root 6411 Aug 16 16:04 127.0.0.1_2.html
-rw-r--r-- 1 root root 48223 Aug 16 16:04 127.0.0.1_2.log
-rw-r--r-- 1 root root 48219 Aug 16 16:04 127.0.0.1_2.old
drwxr-xr-x 2 root root 4096 Aug 16 12:22 images
-rw-r--r-- 1 root root 538 Aug 16 16:04 mrtg-l.png
-rw-r--r-- 1 root root 414 Aug 16 16:04 mrtg-m.png
-rw-r--r-- 1 root root 1759 Aug 16 16:04 mrtg-r.png
-rw-r--r-- 1 root root 4216 Aug 16 16:01 mrtg.cfg
-rw-r--r-- 1 root root 0 Aug 16 16:04 mrtg.ok
[root@uranos data]#
  • 3回実行するとWARNINGが出なくなる.
[root@uranos data]# pwd
/usr/local/mrtg-2/data
[root@uranos data]# ls -la
total 152
drwxr-xr-x 3 root root 4096 Aug 16 16:04 .
drwxr-xr-x 7 root root 4096 Aug 16 14:28 ..
-rw-r--r-- 1 root root 1474 Aug 16 16:04 127.0.0.1_2-day.png
-rw-r--r-- 1 root root 1439 Aug 16 16:04 127.0.0.1_2-month.png
-rw-r--r-- 1 root root 1447 Aug 16 16:04 127.0.0.1_2-week.png
-rw-r--r-- 1 root root 1810 Aug 16 16:04 127.0.0.1_2-year.png
-rw-r--r-- 1 root root 6411 Aug 16 16:04 127.0.0.1_2.html
-rw-r--r-- 1 root root 48223 Aug 16 16:04 127.0.0.1_2.log
-rw-r--r-- 1 root root 48219 Aug 16 16:04 127.0.0.1_2.old
drwxr-xr-x 2 root root 4096 Aug 16 12:22 images
-rw-r--r-- 1 root root 538 Aug 16 16:04 mrtg-l.png
-rw-r--r-- 1 root root 414 Aug 16 16:04 mrtg-m.png
-rw-r--r-- 1 root root 1759 Aug 16 16:04 mrtg-r.png
-rw-r--r-- 1 root root 4216 Aug 16 16:01 mrtg.cfg
-rw-r--r-- 1 root root 0 Aug 16 16:04 mrtg.ok
[root@uranos data]#
  • HTMLファイルとイメージファイルが作成されている.
  • HTMLをWebブラウザで見ると,次のようになっている.

  • データがあまりないので,地をはうようなグラフで面白くない.

6.インデックスページを作成する

  • MRTGでは,複数グラフを見る為のインデックス用のHTMLファイルを作成するツールが付属している.
  • indexmakerコマンドを使って,インデックスファイルを作成する.
[root@uranos mrtg-2]# pwd
/usr/local/mrtg-2 
[root@uranos mrtg-2]# ls -la data
total 152
drwxr-xr-x    3 root     root         4096 Aug 16 17:45 .
drwxr-xr-x    7 root     root         4096 Aug 16 14:28 ..
-rw-r--r--    1 root     root         1951 Aug 16 17:45 127.0.0.1_2-day.png
-rw-r--r--    1 root     root         1439 Aug 16 16:04 127.0.0.1_2-month.png
-rw-r--r--    1 root     root         1558 Aug 16 17:20 127.0.0.1_2-week.png
-rw-r--r--    1 root     root         1810 Aug 16 16:04 127.0.0.1_2-year.png
-rw-r--r--    1 root     root         6527 Aug 16 17:45 127.0.0.1_2.html
-rw-r--r--    1 root     root        48303 Aug 16 17:45 127.0.0.1_2.log
-rw-r--r--    1 root     root        48301 Aug 16 17:40 127.0.0.1_2.old
drwxr-xr-x    2 root     root         4096 Aug 16 12:22 images
-rw-r--r--    1 root     root          538 Aug 16 16:04 mrtg-l.png
-rw-r--r--    1 root     root          414 Aug 16 16:04 mrtg-m.png
-rw-r--r--    1 root     root         1759 Aug 16 16:04 mrtg-r.png
-rw-r--r--    1 root     root         4216 Aug 16 16:01 mrtg.cfg
-rw-r--r--    1 root     root            0 Aug 16 17:45 mrtg.ok
[root@uranos mrtg-2]# /usr/local/mrtg-2/bin/indexmaker ¥
> /usr/local/mrtg-2/data/mrtg.cfg > /usr/local/mrtg-2/data/mrtg.html
[root@uranos mrtg-2]# ls -la data 
total 156
drwxr-xr-x    3 root     root         4096 Aug 16 17:50 .
drwxr-xr-x    7 root     root         4096 Aug 16 14:28 ..
-rw-r--r--    1 root     root         1987 Aug 16 17:50 127.0.0.1_2-day.png
-rw-r--r--    1 root     root         1439 Aug 16 16:04 127.0.0.1_2-month.png
-rw-r--r--    1 root     root         1558 Aug 16 17:20 127.0.0.1_2-week.png
-rw-r--r--    1 root     root         1810 Aug 16 16:04 127.0.0.1_2-year.png
-rw-r--r--    1 root     root         6529 Aug 16 17:50 127.0.0.1_2.html
-rw-r--r--    1 root     root        48307 Aug 16 17:50 127.0.0.1_2.log
-rw-r--r--    1 root     root        48303 Aug 16 17:45 127.0.0.1_2.old
drwxr-xr-x    2 root     root         4096 Aug 16 12:22 images
-rw-r--r--    1 root     root          538 Aug 16 16:04 mrtg-l.png
-rw-r--r--    1 root     root          414 Aug 16 16:04 mrtg-m.png
-rw-r--r--    1 root     root         1759 Aug 16 16:04 mrtg-r.png
-rw-r--r--    1 root     root         4216 Aug 16 16:01 mrtg.cfg
-rw-r--r--    1 root     root         2324 Aug 16 17:50 mrtg.html
-rw-r--r--    1 root     root            0 Aug 16 17:50 mrtg.ok
[root@uranos mrtg-2]#  
  • Apacheに,MRTG用ページの表示設定を行う.
httpd.confへの追加設定内容
#
# Controls who can get stuff from this server.
#
    Order allow,deny
    Allow from all
</Directory>

Alias /uranos_mrtg /usr/local/mrtg-2/data/
<Directory "/usr/local/mrtg-2/data/">
        Options None
        order allow,deny
        allow from all
</Directory>


#
# UserDir: The name of the directory which is appended onto a user's home
# directory if a ~user request is received.
#
<IfModule mod_userdir.c>
    UserDir public_html
</IfModule>
  • Apacheを再起動する.
[root@uranos mrtg-2]# /usr/local/apache/bin/apachectl restart
/usr/local/apache/bin/apachectl restart: httpd restarted
[root@uranos mrtg-2]# ps -ef | grep httpd
root     28528     1  0 14:29 ?        00:00:00 /usr/local/apache/bin/httpd
nobody   31137 28528  0 19:47 ?        00:00:00 /usr/local/apache/bin/httpd
nobody   31138 28528  0 19:47 ?        00:00:00 /usr/local/apache/bin/httpd
nobody   31139 28528  0 19:47 ?        00:00:00 /usr/local/apache/bin/httpd
nobody   31140 28528  0 19:47 ?        00:00:00 /usr/local/apache/bin/httpd
nobody   31141 28528  0 19:47 ?        00:00:00 /usr/local/apache/bin/httpd
root     31143 29290  0 19:47 pts/1    00:00:00 grep httpd
[root@uranos mrtg-2]#  
  • 定期的に実行されるようにcrontabに設定する.
[root@uranos mrtg-2]# crontab -l
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.31163 installed on Thu Oct 27 19:49:53 2005)
# (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $)
*/5 * * * * /usr/local/mrtg-2/bin/mrtg /usr/local/mrtg-2/data/mrtg.cfg 
[root@uranos mrtg-2]#  
  • 画面サイズがリサイズされるようにトップページを書き換える.
[root@uranos mrtg-2]# mv /usr/local/mrtg-2/data/mrtg.html ¥
> /usr/local/mrtg-2/data/mrtg.html.org
[root@uranos mrtg-2]# cat /usr/local/mrtg-2/data/mrtg.html.org | ¥
> sed "s/SRC=/width="100%" SRC=/g" > ¥
> /usr/local/mrtg-2/data/mrtg.html
[root@uranos mrtg-2]#

  • このようにして作成されたmrtg.htmlファイルをブラウザで見てみる.

  • 残念ながら,今回はグラフが1つしかないので,特に面白みはない...
  • 最後に,crontabへ,以下のように登録を行う.
    */5 * * * * /usr/local/mrtg-2/bin/mrtg /usr/local/mrtg-2/data/mrtg.cfg


広告スペース
Google