How to set up MRTG on Fedora 11
- net-snmp をインストール
- 起動
- snmpget できるかチェック
ためしに mrtg を起動
ディレクトリの作成。この下にファイルが生成される。
mrtg を再度起動
warning だからいいや。
[root@arizona ~]# google-chrome /root/mrtg/localhost_2.html ( <- eth0 の情報 )
とれるかチェック
- 空きメモリ量
3回実行 ( 三回目以降エラーがなくなる )
[root@arizona ~]# cat /etc/fedora-release
Fedora release 11 (Leonidas)
[root@arizona ~]# uname -r
2.6.30.10-105.2.23.fc11.x86_64
- net-snmp をインストール
[root@arizona ~]# yum install -y net-snmp.x86_64 net-snmp-utils.x86_64
[root@arizona ~]# snmpd -v
NET-SNMP version: 5.4.2.1
net-snmp-utils に snmpwalk などのツールがはいっている。
snmpd は net-snmp 。
- net-snmp の設定
[root@arizona ~]# egrep -v "^#" /etc/snmp/snmpd.conf | grep -v "^$"
com2sec local localhost public
com2sec mynetwork 0.0.0.0/0 public
group MyRWGroup any local
group MyROGroup any mynetwork
view all included .1 80
access MyRWGroup "" any noauth 0 all all all
syslocation Unknown (edit /etc/snmp/snmpd.conf)
syscontact Root (configure /etc/snmp/snmp.local.conf)
pass .1.3.6.1.4.1.4413.4.1 /usr/bin/ucd5820stat
- 起動
[root@arizona ~]# /etc/init.d/snmpd start
snmpd を起動中: [ OK ]
- snmpget できるかチェック
[root@arizona ~]# snmpbulkwalk -c public -v 2c 127.1 . | head -5
SNMPv2-MIB::sysDescr.0 = STRING: Linux arizona.localdomain 2.6.30.10-105.2.23.fc11.x86_64 #1 SMP Thu Feb 11 07:06:34 UTC 2010 x86_64
SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (12173) 0:02:01.73
SNMPv2-MIB::sysContact.0 = STRING: Root (configure /etc/snmp/snmp.local.conf)
SNMPv2-MIB::sysName.0 = STRING: arizona.localdomain
- MRTG をインストール
[root@arizona ~]# yum install -y mrtg.x86_64
- MRTG の設定
cfgmaker コマンドを使うとインターフェースの情報、コミュニティ名を mrtg.conf に登録してくれる。
[root@arizona ~]# cfgmaker public@localhost > /etc/mrtg/mrtg.cfg
ためしに mrtg を起動
[root@arizona ~]# mrtg /etc/mrtg/mrtg.cfg
-----------------------------------------------------------------------
ERROR: Mrtg will most likely not work properly when the environment
variable LANG is set to UTF-8. Please run mrtg in an environment
where this is not the case. Try the following command to start:
env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg
-----------------------------------------------------------------------
[root@arizona ~]# env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg
Use of uninitialized value $dir in concatenation (.) or string at /usr/bin/mrtg line 2530.
Use of uninitialized value $dir in concatenation (.) or string at /usr/bin/mrtg line 2548.
Use of uninitialized value $dir in concatenation (.) or string at /usr/bin/mrtg line 2564.
ERROR: "WorkDir" not specified in mrtg config file
またもやエラー。
mrtg.conf を編集
下記3つを追加。あとはそのまま。
WorkDir: /root/mrtg
Options[_]: growright, bits
Language:eucjp
ディレクトリの作成。この下にファイルが生成される。
[root@arizona ~]# mkdir /root/mrtg
mrtg を再度起動
warning だからいいや。
[root@arizona ~]# env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg
2010-02-26 02:38:01, Rateup WARNING: /usr/bin/rateup could not read the primary log file for localhost_2
2010-02-26 02:38:01, Rateup WARNING: /usr/bin/rateup The backup log file for localhost_2 was invalid as well
2010-02-26 02:38:01, Rateup WARNING: /usr/bin/rateup Can't remove localhost_2.old updating log file
2010-02-26 02:38:01, Rateup WARNING: /usr/bin/rateup Can't rename localhost_2.log to localhost_2.old updating log file
2010-02-26 02:38:02, Rateup WARNING: /usr/bin/rateup could not read the primary log file for localhost_3
2010-02-26 02:38:02, Rateup WARNING: /usr/bin/rateup The backup log file for localhost_3 was invalid as well
2010-02-26 02:38:02, Rateup WARNING: /usr/bin/rateup Can't remove localhost_3.old updating log file
2010-02-26 02:38:02, Rateup WARNING: /usr/bin/rateup Can't rename localhost_3.log to localhost_3.old updating log file
[root@arizona ~]# ls /root/mrtg/
localhost_2-day.png localhost_2.log localhost_3-year.png mrtg-m.png
localhost_2-month.png localhost_2.old localhost_3.html mrtg-r.png
localhost_2-week.png localhost_3-day.png localhost_3.log
localhost_2-year.png localhost_3-month.png localhost_3.old
localhost_2.html localhost_3-week.png mrtg-l.png
[root@arizona ~]# google-chrome /root/mrtg/localhost_2.html ( <- eth0 の情報 )
- CPU使用率の表示を追加
CPU使用率は以下の OID でとれる。
ssCpuRawUser.0(.1.3.6.1.4.1.2021.11.50.0) <- ユーザのCPU使用率
ssCpuRawSystem.0(.1.3.6.1.4.1.2021.11.52.0) <- システムのCPU使用率
[root@arizona ~]# snmpget -v 2c -c public 127.1 .1.3.6.1.4.1.2021.11.50.0
UCD-SNMP-MIB::ssCpuRawUser.0 = Counter32: 33717
[root@arizona ~]# snmpget -v 2c -c public 127.1 .1.3.6.1.4.1.2021.11.52.0
UCD-SNMP-MIB::ssCpuRawSystem.0 = Counter32: 18507
/etc/mrtg/mrtg.cfg
#CPU Usage
Target[cpu]: .1.3.6.1.4.1.2021.11.50.0&.1.3.6.1.4.1.2021.11.52.0:public@localhost
MaxBytes[cpu]: 100
Options[cpu]: growright, noinfo, nopercent
YLegend[cpu]: CPU usage(%)
ShortLegend[cpu]: (%)
LegendI[cpu]: user
LegendO[cpu]: system
Legend1[cpu]: CPU Usage(user)(%)
Legend2[cpu]: CPU Usage(system)(%)
Title[cpu]: CPU Usage
PageTop[cpu]:CPU Usage
とれるかチェック
[root@arizona ~]# env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg
2010-02-26 02:56:40, Rateup WARNING: /usr/bin/rateup could not read the primary log file for cpu
2010-02-26 02:56:40, Rateup WARNING: /usr/bin/rateup The backup log file for cpu was invalid as well
2010-02-26 02:56:40, Rateup WARNING: /usr/bin/rateup Can't remove cpu.old updating log file
2010-02-26 02:56:40, Rateup WARNING: /usr/bin/rateup Can't rename cpu.log to cpu.old updating log file
[root@arizona ~]# ls /root/mrtg/
cpu-day.png localhost_2-day.png localhost_2.old localhost_3.log
cpu-month.png localhost_2-month.png localhost_3-day.png localhost_3.old
cpu-week.png localhost_2-week.png localhost_3-month.png mrtg-l.png
cpu-year.png localhost_2-year.png localhost_3-week.png mrtg-m.png
cpu.html localhost_2.html localhost_3-year.png mrtg-r.png
cpu.log localhost_2.log localhost_3.html
[root@arizona ~]# google-chrome /root/mrtg/cpu.html
- 空きメモリ量
[root@arizona ~]# snmpget -v 2c -c public 127.1 .1.3.6.1.4.1.2021.4.6.0
UCD-SNMP-MIB::memAvailReal.0 = INTEGER: 2891720 kB
[root@arizona ~]# snmpget -v 2c -c public 127.1 .1.3.6.1.4.1.2021.4.4.0
UCD-SNMP-MIB::memAvailSwap.0 = INTEGER: 8387220 kB
[root@arizona ~]# snmpget -v 2c -c public 127.1 .1.3.6.1.4.1.2021.4.4.0
UCD-SNMP-MIB::memAvailSwap.0 = INTEGER: 8387220 kB
[root@arizona ~]# free
total used free shared buffers cached
Mem: 4018048 1130472 2887576 0 38468 440504
-/+ buffers/cache: 651500 3366548
Swap: 8387220 0 8387220
[root@arizona ~]# cat /etc/mrtg/mrtg.cfg
# Memory Free
Target[mem]: .1.3.6.1.4.1.2021.4.6.0&.1.3.6.1.4.1.2021.4.4.0:public@localhost
MaxBytes1[mem]: 4018048
MaxBytes2[mem]: 8387220
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]: Free Memory[MBytes]
Legend2[mem]: Free Swap Memory[MBytes]
Title[mem]: Free Memory
PageTop[mem]:Free Memory
[root@arizona ~]# env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg
2010-02-26 03:17:21, Rateup WARNING: /usr/bin/rateup Can't remove mem.old updating log file
[root@arizona ~]# ls /root/mrtg/
cpu-day.png localhost_2-month.png localhost_3-week.png mem-year.png
cpu-month.png localhost_2-week.png localhost_3-year.png mem.html
cpu-week.png localhost_2-year.png localhost_3.html mem.log
cpu-year.png localhost_2.html localhost_3.log mem.old
cpu.html localhost_2.log localhost_3.old mrtg-l.png
cpu.log localhost_2.old mem-day.png mrtg-m.png
cpu.old localhost_3-day.png mem-month.png mrtg-r.png
localhost_2-day.png localhost_3-month.png mem-week.png
- 起動スクリプト
mrtg.cfg のワーキングディレクトリを変更
WorkDir: /var/www/mrtg
[root@arizona ~]# cat mrtg.sh
#!/bin/bash
LOCK=/var/www/mrtg/mrtg_l
CONFCACHE=/var/www/mrtg/mrtg.ok
export LANG=ja_JP.UTF-8
mrtg /etc/mrtg/mrtg.cfg --lock-file $LOCK --confcache-file $CONFCACHE
[root@arizona ~]# chmod u+x mrtg.sh
[root@arizona ~]#
3回実行 ( 三回目以降エラーがなくなる )
[root@arizona ~]# ./mrtg.sh
2010-02-26 03:32:35, Rateup WARNING: /usr/bin/rateup could not read the primary log file for localhost_2
2010-02-26 03:32:35, Rateup WARNING: /usr/bin/rateup The backup log file for localhost_2 was invalid as well
2010-02-26 03:32:35, Rateup WARNING: /usr/bin/rateup Can't remove localhost_2.old updating log file
2010-02-26 03:32:35, Rateup WARNING: /usr/bin/rateup Can't rename localhost_2.log to localhost_2.old updating log file
2010-02-26 03:32:36, Rateup WARNING: /usr/bin/rateup could not read the primary log file for localhost_3
2010-02-26 03:32:36, Rateup WARNING: /usr/bin/rateup The backup log file for localhost_3 was invalid as well
2010-02-26 03:32:36, Rateup WARNING: /usr/bin/rateup Can't remove localhost_3.old updating log file
2010-02-26 03:32:36, Rateup WARNING: /usr/bin/rateup Can't rename localhost_3.log to localhost_3.old updating log file
2010-02-26 03:32:36, Rateup WARNING: /usr/bin/rateup could not read the primary log file for cpu
2010-02-26 03:32:36, Rateup WARNING: /usr/bin/rateup The backup log file for cpu was invalid as well
2010-02-26 03:32:36, Rateup WARNING: /usr/bin/rateup Can't remove cpu.old updating log file
2010-02-26 03:32:36, Rateup WARNING: /usr/bin/rateup Can't rename cpu.log to cpu.old updating log file
2010-02-26 03:32:36, Rateup WARNING: /usr/bin/rateup could not read the primary log file for mem
2010-02-26 03:32:36, Rateup WARNING: /usr/bin/rateup The backup log file for mem was invalid as well
2010-02-26 03:32:36, Rateup WARNING: /usr/bin/rateup Can't remove mem.old updating log file
2010-02-26 03:32:36, Rateup WARNING: /usr/bin/rateup Can't rename mem.log to mem.old updating log file
[root@arizona ~]# ./mrtg.sh
2010-02-26 03:32:38, Rateup WARNING: /usr/bin/rateup Can't remove localhost_2.old updating log file
2010-02-26 03:32:38, Rateup WARNING: /usr/bin/rateup Can't remove localhost_3.old updating log file
2010-02-26 03:32:38, Rateup WARNING: /usr/bin/rateup Can't remove cpu.old updating log file
2010-02-26 03:32:38, Rateup WARNING: /usr/bin/rateup Can't remove mem.old updating log file
[root@arizona ~]# ./mrtg.sh
[root@arizona ~]#
[root@arizona ~]# ls /var/www/mrtg/
cpu-day.png localhost_2-week.png localhost_3.log mrtg-l.png
cpu-month.png localhost_2-year.png localhost_3.old mrtg-m.gif
cpu-week.png localhost_2.html mem-day.png mrtg-m.png
cpu-year.png localhost_2.log mem-month.png mrtg-r.gif
cpu.html localhost_2.old mem-week.png mrtg-r.png
cpu.log localhost_3-day.png mem-year.png mrtg-ti.gif
cpu.old localhost_3-month.png mem.html mrtg-ti.png
favicon.ico localhost_3-week.png mem.log mrtg.ok
localhost_2-day.png localhost_3-year.png mem.old
localhost_2-month.png localhost_3.html mrtg-l.gif
cron で定期的に回す
edit
[root@arizona ~]# crontab -e
*/5 * * * * /root/mrtg.shlist
[root@arizona ~]# crontab -l
*/5 * * * * /root/mrtg.sh
- web でみれるようにする
httpd起動時に httpd.conf の設定より conf.d/*.conf を読む。
[root@arizona ~]# egrep -v "^#" /etc/httpd/conf.d/mrtg.conf
Alias /mrtg /var/www/mrtg
Order deny,allow
Deny from all
Allow from all
Allow from 127.0.0.1
Allow from ::1
[root@arizona ~]# apachectl start
- index ページの作成
[root@arizona ~]# indexmaker --columns=1 --addhead='' /etc/mrtg/mrtg.cfg > /var/www/mrtg/index.html
トップ画面
http://127.0.0.1/mrtg/index.html
文字化けしてる。。まぁーいっか。
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.