MRTGのインストール のバックアップ(No.7)


概要

MRTG(The Multi Router Traffic Grapher)

MRTGは、ネットワークのトラフィックやハードウェアの情報を知ることができます。

事前にnet-snmpのインストールを行います

# apt-get install net-snmp
パッケージリストを読みこんでいます... 完了
依存情報ツリーを作成しています... 完了
以下の追加パッケージがインストールされます:
  libelf
以下のパッケージが新たにインストールされます:
  libelf net-snmp
アップグレード: 0 個, 新規インストール: 2 個, 削除: 0 個, 保留: 1 個
2002kB のアーカイブを取得する必要があります。
展開後に 6478kB のディスク容量が追加消費されます。
続行しますか? [Y/n]y
取得:1 http://updates.vinelinux.org 3.1/i386/main libelf 0.8.2-2vl2 [41.0kB]
取得:2 http://updates.vinelinux.org 3.1/i386/plus net-snmp 5.1.1-0vl1 [1961kB]
2002kB を 3s 秒で取得しました (577kB/s)
変更を適用しています...
Preparing...                ########################################### [100%]
   1:libelf                 ########################################### [ 50%]
   2:net-snmp               ########################################### [100%]
完了

snmpd.confの編集

# vi /etc/snmp/snmpd.conf
#com2sec notConfigUser  default       public
com2sec local localhost private
com2sec mynetwork 192.168.0.0/24 public

#group   notConfigGroup v1           notConfigUser
#group   notConfigGroup v2c           notConfigUser
group MyROGroup v1 mynetwork
group MyROGroup v2c mynetwork

#view    systemview    included   .1.3.6.1.2.1.1
#view    systemview    included   .1.3.6.1.2.1.25.1.1
view all included .1 80

#access  notConfigGroup ""      any       noauth    exact  systemview none none
access MyROGroup "" any noauth exact all none none
access MyRWGroup "" any noauth exact all all none

#disk / 10000
disk / 10000

snmpdの起動

# /etc/rc.d/init.d/snmpd start
snmpdを起動中:                                             [  OK  ]

自動起動の設定

# chkconfig --level 3 snmpd on
# chkconfig --list snmpd
snmpd           0:off   1:off   2:off   3:on    4:off   5:off   6:off

gdも必要みたいなのでインストールします。

# apt-get install gd gd-devel
パッケージリストを読みこんでいます... 完了
依存情報ツリーを作成しています... 完了
以下の追加パッケージがインストールされます:
  XOrg-libs freetype2 libexpat
以下のパッケージが新たにインストールされます:
  XOrg-libs freetype2 gd gd-devel libexpat
アップグレード: 0 個, 新規インストール: 5 個, 削除: 0 個, 保留: 1 個
2603kB のアーカイブを取得する必要があります。
展開後に 6388kB のディスク容量が追加消費されます。
続行しますか? [Y/n]y
取得:1 http://updates.vinelinux.org 3.1/i386/main libexpat 1.95.7-1vl1 [70.4kB]
取得:2 http://updates.vinelinux.org 3.1/i386/main freetype2 2.1.7-0vl4 [274kB]
取得:3 http://updates.vinelinux.org 3.1/i386/updates XOrg-libs 6.7.0-0vl6.1 [2068kB]
取得:4 http://updates.vinelinux.org 3.1/i386/updates gd 2.0.27-0vl2 [95.5kB]
取得:5 http://updates.vinelinux.org 3.1/i386/updates gd-devel 2.0.27-0vl2 [95.6kB]
2603kB を 16s 秒で取得しました (161kB/s)
変更を適用しています...
Preparing...                ########################################### [100%]
   1:libexpat               ########################################### [ 20%]
   2:freetype2              ########################################### [ 40%]
   3:XOrg-libs              ########################################### [ 60%]
   4:gd                     ########################################### [ 80%]
   5:gd-devel               ########################################### [100%]
完了

MRTGのダウンロード、解凍

# wget http://people.ee.ethz.ch/~oetiker/webtools/mrtg/pub/mrtg-2.12.1.tar.gz
--17:04:47--  http://people.ee.ethz.ch/%7Eoetiker/webtools/mrtg/pub/mrtg-2.12.1.tar.gz
           => `mrtg-2.12.1.tar.gz'
people.ee.ethz.ch をDNSに問いあわせています... 129.132.2.203
people.ee.ethz.ch[129.132.2.203]:80 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 1,134,805 [application/x-tar]

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

17:04:54 (170.99 KB/s) - `mrtg-2.12.1.tar.gz' を保存しました [1134805/1134805]

# tar zxf mrtg-2.12.1.tar.gz
# cd mrtg-2.12.1/

コンフィギュア、メイク

# ./configure --prefix=/usr/local/mrtg-2

# make
# make install

configファイルの作成

# /usr/local/mrtg-2/bin/cfgmaker --output=/usr/local/mrtg-2/lib/mrtg.cfg [email protected]

メモリ容量の確認

configファイルに記述する値を確認します

# free
              合計     使用済   空き領域   共有領域    バッファ キャッシュ
Mem:        376728     212256     164472          0      45460      71048
-/+ バッファ:           95748     280980
Swap:       779112          0     779112
              ↑ここの値をメモる(Mem/Swap)

configファイルの編集

# vi /usr/local/mrtg-2/lib/mrtg.cfg
#  for UNIX
WorkDir: /home/httpd/mrtg

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

Language:eucjp


### CPU Load Average ###
Target[cpu]: .1.3.6.1.4.1.2021.10.1.5.1&.1.3.6.1.4.1.2021.10.1.5.2:[email protected]
MaxBytes[cpu]: 100
Unscaled[cpu]: dwmy
Options[cpu]: gauge, absolute, growright, noinfo, nopercent
YLegend[cpu]: CPU Load(%)
ShortLegend[cpu]: (%)
LegendI[cpu]: 1分間平均
LegendO[cpu]: 5分間平均
Legend1[cpu]: 1分間平均(%)
Legend2[cpu]: 5分間平均(%)
Title[cpu]: CPU使用率
PageTop[cpu]: <H1>CPU使用率</H1>

### Memory Free ####
Target[mem]: .1.3.6.1.4.1.2021.4.6.0&.1.3.6.1.4.1.2021.4.4.0:[email protected]
MaxBytes1[mem]: 376728                          ←freeで調べた値を記述する(Mem)
MaxBytes2[mem]: 779112                          ←freeで調べた値を記述する(Swap)
Unscaled[mem]: dwmy
Options[mem]: gauge, absolute, growright, noinfo
YLegend[mem]: Mem Free(Bytes)
ShortLegend[mem]: Bytes
kilo[mem]: 1024
kMG[mem]: k,M,G,T,P
LegendI[mem]: Real
LegendO[mem]: Swap
Legend1[mem]: 空き物理メモリ[MBytes]
Legend2[mem]: 空きスワップメモリ[MBytes]
Title[mem]: 空きメモリ量
PageTop[mem]: <H1>空きメモリ量</H1>

### Disk Used ####
Target[disk]: .1.3.6.1.4.1.2021.9.1.9.1&.1.3.6.1.4.1.2021.9.1.9.1:[email protected]
MaxBytes[disk]: 100
Unscaled[disk]: dwmy
Options[disk]: gauge, absolute, growright, nopercent, noinfo
YLegend[disk]: Disk Used(%)
ShortLegend[disk]: (%)
LegendI[disk]: / Disk used
LegendO[disk]: / Disk Used
Legend1[disk]: / Disk used
Legend2[disk]: / Disk used
Title[disk]: ディスク使用率
PageTop[disk]: <H1>ディスク使用率</H1>

実行

# /usr/local/mrtg-2/bin/mrtg /usr/local/mrtg-2/lib/mrtg.cfg

エラーが出なくなるまで何回か実行する。

インデックスページを作る

# /usr/local/mrtg-2/bin/indexmaker --columns=1 \
--addhead="<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=euc-jp\">" \
/usr/local/mrtg-2/lib/mrtg.cfg > /home/httpd/mrtg/index.html

httpd.confの編集

# vi /usr/local/apache2/conf/httpd.conf

一番最後に追加

Alias /mrtg /home/httpd/mrtg
<Location /mrtg>
    Order deny,allow
    Deny from all
    Allow from All
    Allow from ::1
</Location>

apacheの再起動

# /etc/init.d/apache2 restart
httpdを停止中:                                             [  OK  ]
httpdを起動中:                                             [  OK  ]

動作の確認

http://ホスト名/mrtg/にアクセスして表示されればOK。

定期的に実行する

# crontab -e

以下を追加

0-59/5 * * * * /usr/local/mrtg-2/bin/mrtg /usr/local/mrtg-2/lib/mrtg.cfg

5分ごとに実行します。

tips

HDDの温度監視をしたいとき

  • smartmontoolsのインストール
    # apt-get install smartmontools
    パッケージリストを読みこんでいます... 完了
    依存情報ツリーを作成しています... 完了
    以下のパッケージが新たにインストールされます:
      smartmontools
    アップグレード: 0 個, 新規インストール: 1 個, 削除: 0 個, 保留: 1 個
    351kB のアーカイブを取得する必要があります。
    展開後に 608kB のディスク容量が追加消費されます。
    取得:1 http://updates.vinelinux.org 3.1/i386/plus smartmontools 5.33-1vl0.6 [351kB]
    351kB を 1s 秒で取得しました (196kB/s)
    変更を適用しています...
    Preparing...                ########################################### [100%]
    Note that you can use a configuration file /etc/smartd.conf to control the
    startup behavior of the smartd daemon.  See man 8 smartd for details.
    Run "/sbin/chkconfig --add smartd", to start smartd service on system boot
       1:smartmontools          ########################################### [100%]
    Run "/etc/rc.d/init.d/smartd start" to start smartd service now.
    完了
  • /dev/hdaの情報を表示
    # smartctl -a /dev/hda
    smartctl version 5.33 [i686-pc-linux-gnu] Copyright (C) 2002-4 Bruce Allen
    Home page is http://smartmontools.sourceforge.net/
    :
    :
    193 Load_Cycle_Count        0x0012   100   100   050    Old_age   Always       -       248
    194 Temperature_Celsius     0x0002   122   122   000    Old_age   Always       -       45 (Lifetime Min/Max 13/61)
    196 Reallocated_Event_Count 0x0032   100   100   000    Old_age   Always       -       0
    :
    :
    194 Temperature_Celsius・・・ が表示されればOKです。右っ側の45という数字が現在の温度です。
  • 自動起動の設定
    # chkconfig --level 3 smartd on
    # chkconfig --list smartd
    snmpd           0:off   1:off   2:off   3:on    4:off   5:off   6:off
  • 温度取得スクリプトの作成
    # vi /usr/local/mrtg-2/hdd_temp.cgi
    新規
    #!/usr/bin/perl
    #
    $machine="tp390x.niwaka.ddo.jp";
    $smart=`/usr/sbin/smartctl -a /dev/hda`;
    @smart = split(/\n/, $smart);
    foreach $data (@smart){
        if($data =~ /Temperature_Celsius(.*?)0x(\d+)(.*?)(\d+)(.*?)(\d+)(.*?)(\d+)(.*?)(\d+)/)
    {
            $temp = $10;
        }
    }
    $utime = `uptime`;
    $utime =~ /up(.*?),/;
    $uptime = $1;
    $uptime =~ s/^\s*//g;
    
    print "$temp\n";
    print "$temp\n";
    # Print uptime
    print "$uptime\n";
    # Print machine name for mrtg
    print "$machine\n";
    exit;
  • 実行権限を与える
    # chmod 755 /usr/local/mrtg-2/hdd_temp.cgi
  • mrcg.cfgの編集
    # vi /usr/local/mrtg-2/lib/mrtg.cfg
    追加
    ### HDD Temperature ###
    Target[htemp]: `perl /usr/local/mrtg-2/hdd_temp.cgi`
    MaxBytes[htemp]: 60
    Options[htemp]: gauge, growright, absolute, integer, nopercent, noinfo
    Unscaled[htemp]: dwmy
    YLegend[htemp]: Temperature
    ShortLegend[htemp]: deg.
    LegendI[htemp]: TEMP&nbsp;
    LegendO[htemp]: TEMP&nbsp;
    Legend1[htemp]: HDD温度
    Legend2[htemp]: HDD温度
    Title[htemp]: HDDの温度
    PageTop[htemp]: <H1>HDDの温度</H1>
  • 実行
    # /usr/local/mrtg-2/bin/mrtg /usr/local/mrtg-2/lib/mrtg.cfg
  • インデックスページを作る
    # /usr/local/mrtg-2/bin/indexmaker --columns=1 \
    --addhead="<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=euc-jp\">" \
    /usr/local/mrtg-2/lib/mrtg.cfg > /home/httpd/mrtg/index.html

コメント

コメントはありません。 MRTG/コメント?

お名前: