UnixPower on Networking
  http://www.unix-power.net/

 
  Top - Solaris8 - Solaris MRTG



MRTGはネットワークの状態などをグラフ化するSNMPマネージャです。これにより、ネットワークの状態が視覚的に把握できるようになります。以下のソフトが必要になります。


net-snmp5.0.6
http://net-snmp.sourceforge.net/


mrtg2.9.22
http://www.mrtg.jp/doc/


zlib1.1.4
http://www.gzip.org/zlib/


libpng-1.2.5.tar.gz
http://www.libpng.org/pub/png/libpng.html


jpegsrc.v6b.tar.gz
ftp://ftp.uu.net/graphics/jpeg/


gd-1.8.4.tar.gz
http://www.ijg.org/


■Net-SNMPの導入


次のコマンドでインストールと設定を行います。


# tar xvzf net-snmp-5.0.6.tar.gz
# cd net-snmp-5.0.6
# ./configure
以下の4つの質問を受けます.不都合が無ければデフォルトのままで…
 
System Contact Information
(root@prism-r.com): ←管理者のメールアドレス
 
System Location (Unknown): ←サーバの名前?
 
Location to write persistent information (/var/net-snmp): ←ログの置き場所
 
Location to write logfile
(/var/log/snmpd.log): ←情報ファイルの置き場所
$ make
$ make install
$ cp EXAMPLE.conf /usr/local/share/snmp/snmpd.conf
$ chmod 600 /usr/local/share/snmp/snmpd.conf
$ vi /usr/local/share/snmp/snmpd.conf


設定ファイルの中身は私の場合、次のようになってます。


###############################################################################
#
# EXAMPLE.conf:
#   An example configuration file for configuring the ucd-snmp snmpd agent.
#
###############################################################################
#
# This file is intended to only be an example.  If, however, you want
# to use it, it should be placed in /usr/local/share/snmp/snmpd.conf.
# When the snmpd agent starts up, this is where it will look for it.
#
# You might be interested in generating your own snmpd.conf file using
# the "snmpconf" program (perl script) instead.  It's a nice menu
# based interface to writing well commented configuration files.  Try it!
#
# Note: This file is automatically generated from EXAMPLE.conf.def.
# Do NOT read the EXAMPLE.conf.def file! Instead, after you have run
# configure & make, and then make sure you read the EXAMPLE.conf file
# instead, as it will tailor itself to your configuration.

# All lines beginning with a '#' are comments and are intended for you
# to read.  All other lines are configuration commands for the agent.
#
# PLEASE: read the snmpd.conf(5) manual page as well!
#

###############################################################################
# Access Control
###############################################################################

# YOU SHOULD CHANGE THE "COMMUNITY" TOKEN BELOW TO A NEW KEYWORD ONLY
# KNOWN AT YOUR SITE.  YOU *MUST* CHANGE THE NETWORK TOKEN BELOW TO
# SOMETHING REFLECTING YOUR LOCAL NETWORK ADDRESS SPACE.

# By far, the most common question I get about the agent is "why won't
# it work?", when really it should be "how do I configure the agent to
# allow me to access it?"
#
# By default, the agent responds to the "public" community for read
# only access, if run out of the box without any configuration file in
# place.  The following examples show you other ways of configuring
# the agent so that you can change the community names, and give
# yourself write access as well.
#
# The following lines change the access permissions of the agent so
# that the COMMUNITY string provides read-only access to your entire
# NETWORK (EG: 10.10.10.0/24), and read/write access to only the
# localhost (127.0.0.1, not its real ipaddress).
#
# For more information, read the FAQ as well as the snmpd.conf(5)
# manual page.

####
# First, map the community name (COMMUNITY) into a security name
# (local and mynetwork, depending on where the request is coming
# from):

#       sec.name  source          community
com2sec local     localhost       private
com2sec mynetwork xxx.xxx.xxx.xxx/32      xxxxx

####
# Second, map the security names into group names:

#               sec.model  sec.name
#group MyRWGroup        v1         local
#group MyRWGroup        v2c        local
#group MyRWGroup        usm        local
group MyROGroup v1         mynetwork
group MyROGroup v2c        mynetwork
group MyROGroup usm        mynetwork

####
# Third, create a view for us to let the groups have rights to:

#           incl/excl subtree                          mask
view all    included  .1                               80

####
# Finally, grant the 2 groups access to the 1 view with different
# write permissions:

#                context sec.model sec.level match  read   write  notif
access MyROGroup ""      any       noauth    exact  all    none   none
access MyRWGroup ""      any       noauth    exact  all    all    none

# -----------------------------------------------------------------------------

###############################################################################
# System contact information
#

# It is also possible to set the sysContact and sysLocation system
# variables through the snmpd.conf file.  **PLEASE NOTE** that setting
# the value of these objects here makes these objects READ-ONLY
# (regardless of any access control settings).  Any attempt to set the
# value of an object whose value is given here will fail with an error
# status of notWritable.

syslocation Right here, right now.
syscontact Me <info@xxxx.co.jp>

# Example output of snmpwalk:
#   % snmpwalk -v 1 -c public localhost system
#   system.sysDescr.0 = "SunOS name sun4c"
#   system.sysObjectID.0 = OID: enterprises.ucdavis.ucdSnmpAgent.sunos4
#   system.sysUpTime.0 = Timeticks: (595637548) 68 days, 22:32:55
#   system.sysContact.0 = "Me <me@somewhere.org>"
#   system.sysName.0 = "name"
#   system.sysLocation.0 = "Right here, right now."
#   system.sysServices.0 = 72

# -----------------------------------------------------------------------------

###############################################################################
# Process checks.
#
#  The following are examples of how to use the agent to check for
#  processes running on the host.  The syntax looks something like:
#
#  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.

#
#  Examples:
#
#  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


----------------------------省略----------------------



#disk / 10000
disk /home

# % snmpwalk -v 1 -c public localhost .1.3.6.1.4.1.2021.9
# enterprises.ucdavis.diskTable.dskEntry.diskIndex.1 = 0
# enterprises.ucdavis.diskTable.dskEntry.diskPath.1 = "/" Hex: 2F
# enterprises.ucdavis.diskTable.dskEntry.diskDevice.1 = "/dev/dsk/c201d6s0"
# enterprises.ucdavis.diskTable.dskEntry.diskMinimum.1 = 10000
# enterprises.ucdavis.diskTable.dskEntry.diskTotal.1 = 837130
# enterprises.ucdavis.diskTable.dskEntry.diskAvail.1 = 316325
# enterprises.ucdavis.diskTable.dskEntry.diskUsed.1 = 437092
# enterprises.ucdavis.diskTable.dskEntry.diskPercent.1 = 58
# enterprises.ucdavis.diskTable.dskEntry.diskErrorFlag.1 = 0
# enterprises.ucdavis.diskTable.dskEntry.diskErrorMsg.1 = ""

# -----------------------------------------------------------------------------

###############################################################################
# load average checks
#

# load [1MAX=DEFMAXLOADAVE] [5MAX=DEFMAXLOADAVE] [15MAX=DEFMAXLOADAVE]
#
# 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.

# Check for loads:
load 12 14 14


----------------------------省略----------------------


そして次のコマンドで起動します。


# /usr/local/sbin/snmpd



■ライブラリのインストール


続いてライブラリを片っ端からインストールしていきます。


・zlib


# tar zxvf zlib.tar.gz
# cd zlib-1.1.4
# ./configure
# make
# makeinstall


・libpng


# tar zxvf libpng-1.2.5.tar.gz
# cd libpng-1.2.5
# cp scripts/makefile.std Makefile
# make
# make install


・libjpeg


# tar zxvf jpegsrc.v6b.tar.gz
# cd jpeg-6b
# ./configure
※libjpegはヘッダのみを必要とする為,makeは不要!


・gd


# tar zxvfp gd-1.8.4.tar.gz
# cd gd-1.8.4
# vi Makefile
INCLUDEDIRS にlibjpegのパスを追加
修正イメージ:
INCLUDEDIRS=-I. -I~.. -I/usr/local/include -I../jpeg-6b
# make
# make install


■MRTGのインストール


これまたいつもと同じインストール


# tar zxvfp mrtg-2.9.22.tar.gz
# cd mrtg-2.9.22
# ./configure --with-gd=../gd-1.8.4 --with-z=../zlib-1.1. --with-png=../libpng-1.2.5
# make
# make install
・出力htmlの日本語化
# ./mergelocale.pl skeleton.pm0 eucjp.pmd
# ./mergelocale.pl skeleton.pm0 iso2022JP.pmd
# cp locales_mrtg.pm /usr/local/mrtg-2/lib/


■設定


まずベースとなるファイルを作成し、実行します。


# mkdir /usr/local/mrtg-2/data
# cd /usr/local/mrtg-2/data
# cp /usr/local/mrtg-2/share/mrtg2/icons/* /home/www/htdocs/mrtg
# /usr/local/mrtg-2/bin/cfgmaker COMMUNITY@IP Address > mrtg.cfg
# cd /usr/local/mrtg/data
# /usr/local/mrtg/bin/mrtg mrtg.cfg


生成されたmrtg.cfgから少し編集する必要があります。私のmrtg.cfgは次のようになっています。


# Created by
# /usr/local/mrtg-2/bin/cfgmaker xxxxxx@xxx.xxx.xxx.xxx
### Global Config Options

#  for UNIX

WorkDir: /home/www/htdocs/mrtg
Language: eucjp
Refresh: 300

#  or for NT
# WorkDir: c:\mrtgdata
### Global Defaults
#  to get bits instead of bytes and graphs growing to the right
Options[_]: growright, bits

######################################################################
# System: gx15.woo.ne.jp
# Description: Solaris8 gx15.woo.ne.jp #2: Sun Jan i386

# Contact: Me <yamashita@woo.ne.jp>
# Location: My Server(gx15.woo.ne.jp) Solaris 8
######################################################################
### Interface 1 >> Descr: 'fxp0' | Name: '' | Ip: 'xxx.xxx.xxx.xxx' | Eth: '' ### Target[xxx.xxx.xxx.xxx_1]: 1:xxxxxx@xxx.xxx.xxx.xxx0: SetEnv[xxx.xxx.xxx.xxx_1]: MRTG_INT_IP="xxx.xxx.xxx.xxx" MRTG_INT_DESCR="fxp0" MaxBytes[xxx.xxx.xxx.xxx_1]: 12500000 Title[xxx.xxx.xxx.xxx_1]: Traffic Analysis for 1 -- gx15.woo.ne.jp PageTop[xxx.xxx.xxx.xxx_1]: <H1>Traffic Analysis for 1 -- gx15.woo.ne.jp</H1> <TABLE> <TR><TD>System:</TD> <TD>gx15.woo.ne.jp in My Server(gx15.woo.ne.jp) FreeBSD 4.3</TD></TR> <TR><TD>Maintainer:</TD> <TD>Me &lt;yamashita@woo.ne.jp&gt;</TD></TR> <TR><TD>Description:</TD><TD>fxp0 </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> <TR><TD>Ip:</TD> <TD>xxx.xxx.xxx.xxx ()</TD></TR> </TABLE>


最初の2回くらいの実行はエラーメッセージが出るが,これは過去のログがない為.しかし,3回目以降もエラーメッセージが出力される場合は設定を見直しましょう.


■運用登録


# /usr/local/mrtg-2/bin/indexmaker mrtg.cfg > index.html
# crontab -e
*/5 * * * * /usr/local/mrtg/bin/mrtg /usr/local/mrtg/data/mrtg.cfg


とりあえず以上で全ての設定が完了です。あとはブラウザから次のような画面が見れればOKです。



■さらに進んだ設定


ネットワークのトラフィックだけでなく、CPU負荷率、メモリ使用量、ディスク使用量についてもグラフ化してみます。設定ファイルの内容については、SNMPの知識が要求され複雑なので、設定ファイルのサンプルを掲載しておきます


cpu.cfg

CPU負荷率の監視

mem.cfg

メモリ使用量の監視

disk.cfg

ディスク使用率の監視


このサンプル設定ファイルでは、MRTGをデーモンとして起動するように設定されています。正しく配置したら、MRTGを起動します。


# /usr/local/mrtg-2/bin/mrtg /usr/local/mrtg-2/data/cpu.cfg
# /usr/local/mrtg-2/bin/mrtg /usr/local/mrtg-2/data/memory.cfg
# /usr/local/mrtg-2/bin/mrtg /usr/local/mrtg-2/data/disk.cfg 


次にindex.htmlファイルを生成します。


# bin/indexmaker data/cpu.cfg > data/cpu.html
# bin/indexmaker data/memory.cfg > data/memory.html
# bin/indexmaker data/disk.cfg > data/disk.html 


但し、メモリに関しては上記のやりかたでは正確なデータをとることができなかったので以下のやり方をお勧めします。(pdkshがインストールされているのが前提)


#!/bin/ksh

IP=$1
set -A SYS `/usr/local/bin/snmpwalk -v 1 -c xxxxxx $IP .1.3.6.1.2.1.1.1`

set -A MTS `/usr/local/bin/snmpwalk -v 1 -c xxxxxx $IP .1.3.6.1.4.1.2021.4.3.0`
set -A MAS `/usr/local/bin/snmpwalk -v 1 -c xxxxxx $IP .1.3.6.1.4.1.2021.4.4.0`
set -A MTR `/usr/local/bin/snmpwalk -v 1 -c xxxxxx $IP .1.3.6.1.4.1.2021.4.5.0`
set -A MAR `/usr/local/bin/snmpwalk -v 1 -c xxxxxx $IP .1.3.6.1.4.1.2021.4.6.0`
MEMR=`/usr/bin/expr ${MTR[3]} - ${MAR[3]}`
SWAR=`/usr/bin/expr ${MTS[3]} - ${MAS[3]}`
HOST=$SYS[3]

echo $MEMR
echo $SWAR
echo ""
echo $HOST


xxxxxxにはコミュニティ名に置き換えてください。これを実行ファイルとしてbinディレクトリ以下に保存します。そしてcfgファイルを以下のようにおきかえます。


WorkDir: /home/www/Control/mrtg/mem
Refresh: 300
Language: eucjp
Options[_]: gauge, absolute, growright, noinfo
Directory[_]: memory
YLegend[_]: Memory Used(Bytes)
ShortLegend[_]: (Bytes)
Legend1[_]: Real Memory
Legend2[_]: Swap Memory
LegendI[_]: Real
LegendO[_]: Swap
Unscaled[_]: dwmy
kilo[_]: 1024
kMG[_]: k,M,G,T,P

Target[192.168.5.1_mem]: `/usr/local/mrtg-2/bin/mem.sh 192.168.5.1`
MaxBytes[192.168.5.1_mem]: 128000
MaxBytes2[192.168.5.1_mem]: 256000
Title[192.168.5.1_mem]: Memory Used for www.xxxxx.co.jp
PageTop[192.168.5.1_mem]: <H1>Memory Used for www.xxxxxx.co.jp</H1>
 <TABLE>
   <TR><TD>System:</TD><TD>www.xxxxxx.co.jp</TD></TR>
   <TR><TD>Maintainer:</TD><TD>webmaster@xxxxxx.co.jp</TD></TR>
   <TR><TD>Ip:</TD><TD>192.168.5.1</TD></TR>
  </TABLE>



 
 Copyright(C) 2003-2015 UnixPower on Networking All rights reserved.