- 追加された行はこの色です。
- 削除された行はこの色です。
#contents
*net-snmp, mrtgをyumでインストール [#q561aa2f]
# yum install net-snmp net-snmp-utils mrtg
*net-snmpのセットアップ [#u26c7088]
# vi /etc/snmp/snmpd.conf
communityはパスワードみたいなものなので適宜変更すること
# sec.name source community
com2sec notConfigUser localhost public
# groupName securityModel securityName
group notConfigGroup v1 notConfigUser
group notConfigGroup v2c notConfigUser
view systemview included .1
# group context sec.model sec.level prefix read write notif
access notConfigGroup "" any noauth exact systemview none none
proc mountd
proc ntalkd 4
proc sendmail 10 1
proc httpd
disk / 10000
net-snmpだけを動かして、別のサーバにてMRTGを動かす場合
# sec.name source community
com2sec notConfigUser localhost public
com2sec notConfigUser 192.168.0.0/28 public
# groupName securityModel securityName
group notConfigGroup v1 notConfigUser
group notConfigGroup v2c notConfigUser
group ConfigGroup v1 ConfigUser
group ConfigGroup v2c ConfigUser
view systemview included .1
# group context sec.model sec.level prefix read write notif
access notConfigGroup "" any noauth exact systemview none none
access ConfigGroup "" any noauth exact systemview none none
proc mountd
proc ntalkd 4
proc sendmail 10 1
proc httpd
disk / 10000
httpd はSSLを利用しているとプロセス数が取れないかもしれない~
その場合は libhttpd.ep を指定します
# /etc/rc.d/init.d/snmpd stop
# /etc/rc.d/init.d/snmpd start
確認~
すらずらっとデータが出力されればOK
# snmpwalk -c public -v 1 localhost .1
*トラフィック確認設定 [#v4934ee9]
*mrtg設定 [#v4934ee9]
# vi /etc/mrtg/traffic.cfg
# vi /etc/mrtg/mrtg.cfg
WorkDir: /home/user/public_html/mrtg
HtmlDir: /home/user/public_html/mrtg
ImageDir: /home/user/public_html/mrtg/images
LogDir: /home/user/public_html/mrtg/logs
#ThreshDir: /home/user/public_html/mrtg/thresh
RunAsDaemon: Yes
Interval: 5
Refresh: 300
Directory[_]: traffic
Target[index]: 2:public@localhost
MaxBytes[index]: 1250000
Title[index]: Traffic Analysis
PageTop[index]: <H1>Traffic Analysis</H1>
*CPU確認設定 [#g88a5722]
# vi /etc/mrtg/cpu.cfg
WorkDir: /home/user/public_html/mrtg
RunAsDaemon: Yes
Interval: 5
Refresh: 300
Options[_]: gauge,absolute,integer,nopercent
Directory[_]: cpu
MaxBytes[_]: 100
YLegend[_]: CPU Load Average (%)
Legend1[_]: 1 min CPU Load Avalage
Legend2[_]: 5 min CPU Load Avalage
LegendI[_]: 1min
LegendO[_]: 5min
ShortLegend[_]: percent (%)
Unscaled[_]: dwmy
# Traffic
Target[index]: .1.3.6.1.4.1.2021.10.1.5.1&.1.3.6.1.4.1.2021.10.1.5.1:public@localhost
Title[index]: CPU Load Average
PageTop[index]: <H1>CPU Load Average</H1>
*メモリ確認設定 [#ha49ed9c]
topコマンドでMem, Swapを調べ、それぞれMaxBytes1,MaxBytes2に設定
# vi /etc/mrtg/memory.cfg
WorkDir: /home/user/public_html/mrtg
RunAsDaemon: Yes
Interval: 5
Refresh: 300
Options[_]: gauge,absolute
Directory[_]: memory
YLegend[_]: Memory Used(Bytes)
ShortLegend[_]: (Bytes)
Legend1[_]: Real Memory
Legend2[_]: Swap Memory
LegendI[_]: Real
LegendO[_]: Swap
Unscaled[_]: dwmy
kMG[_]: k,M,G,T,P
Target[traffic]: 2:public@localhost
MaxBytes[traffic]: 1250000
Title[traffic]: Traffic Analysis
PageTop[traffic]: <H1>Traffic Analysis</H1>
Target[index]: 1.3.6.1.4.1.2021.4.6.0&1.3.6.1.4.1.2021.4.4.0:public@localhost
MaxBytes1[index]: 254468
MaxBytes2[index]: 257032
Title[index]: Memory Used
PageTop[index]: <H1>Memory Used</H1>
*ディスク容量確認設定 [#md390e2f]
# vi /etc/mrtg/disk.cfg
WorkDir: /home/user/public_html/mrtg
RunAsDaemon: Yes
Interval: 5
Refresh: 300
Options[_]: gauge,absolute,nopercent
Directory[_]: disk
MaxBytes[_]: 100
YLegend[_]: Disk Used (%)
LegendI[_]: / Disk used
LegendO[_]: / Disk Used
Legend1[_]: / Disk used
Legend2[_]: / Disk used
ShortLegend[_]: percent (%)
Unscaled[_]: dwmy
# CPU
Target[index]: .1.3.6.1.4.1.2021.9.1.9.1&.1.3.6.1.4.1.2021.9.1.9.1:public@localhost
Title[index]: Disk Used
PageTop[index]: <H1>Disk Used</H1>
*httpプロセス確認設定 [#y7308c4e]
# vi /etc/mrtg/httpd.cfg
WorkDir: /home/user/public_html/mrtg
RunAsDaemon: Yes
Interval: 5
Refresh: 300
Options[_]: gauge,absolute,nopercent
Directory[_]: httpd
MaxBytes[_]: 150
YLegend[_]: Number of httpd
LegendI[_]: httpd
LegendO[_]: httpd
Legend1[_]: httpd
Legend2[_]: httpd
ShortLegend[_]: process
Unscaled[_]: dwmy
Options[cpu]: gauge,absolute,integer,nopercent
MaxBytes[cpu]: 100
YLegend[cpu]: CPU Load Average (%)
Legend1[cpu]: 1 min CPU Load Avalage
Legend2[cpu]: 5 min CPU Load Avalage
LegendI[cpu]: 1min
LegendO[cpu]: 5min
ShortLegend[cpu]: percent (%)
Unscaled[cpu]: dwmy
Target[cpu]: .1.3.6.1.4.1.2021.10.1.5.1&.1.3.6.1.4.1.2021.10.1.5.1:public@localhost
Title[cpu]: CPU Load Average
PageTop[cpu]: <H1>CPU Load Average</H1>
Target[index]: .1.3.6.1.4.1.2021.2.1.5.4&.1.3.6.1.4.1.2021.2.1.5.4:public@localhost
Title[index]: Number of httpd
PageTop[index]: <H1>Number of httpd</H1>
# Memory
Options[memory]: gauge,absolute
YLegend[memory]: Memory Used(Bytes)
ShortLegend[memory]: (Bytes)
Legend1[memory]: Real Memory
Legend2[memory]: Swap Memory
LegendI[memory]: Real
LegendO[memory]: Swap
Unscaled[memory]: dwmy
kMG[memory]: k,M,G,T,P
Target[memory]: 1.3.6.1.4.1.2021.4.6.0&1.3.6.1.4.1.2021.4.4.0:public@localhost
MaxBytes1[memory]: 254468
MaxBytes2[memory]: 257032
Title[memory]: Memory Used
PageTop[memory]: <H1>Memory Used</H1>
# Disk
Options[disk]: gauge,absolute,nopercent
MaxBytes[disk]: 100
YLegend[disk]: Disk Used (%)
LegendI[disk]: / Disk used
LegendO[disk]: / Disk Used
Legend1[disk]: / Disk used
Legend2[disk]: / Disk used
ShortLegend[disk]: percent (%)
Unscaled[disk]: dwmy
Target[disk]: .1.3.6.1.4.1.2021.9.1.9.1&.1.3.6.1.4.1.2021.9.1.9.1:public@localhost
Title[disk]: Disk Used
PageTop[disk]: <H1>Disk Used</H1>
# Http
Options[httpd]: gauge,absolute,nopercent
MaxBytes[httpd]: 150
YLegend[httpd]: Number of httpd
LegendI[httpd]: httpd
LegendO[httpd]: httpd
Legend1[httpd]: httpd
Legend2[httpd]: httpd
ShortLegend[httpd]: process
Unscaled[httpd]: dwmy
Target[httpd]: .1.3.6.1.4.1.2021.2.1.5.4&.1.3.6.1.4.1.2021.2.1.5.4:public@localhost
Title[httpd]: Number of httpd
PageTop[httpd]: <H1>Number of httpd</H1>
*自動起動の設定 [#wcfe9146]
# vi /etc/rc.d/rc.local
/usr/bin/mrtg /etc/mrtg/traffic.cfg
/usr/bin/mrtg /etc/mrtg/cpu.cfg
/usr/bin/mrtg /etc/mrtg/memory.cfg
/usr/bin/mrtg /etc/mrtg/disk.cfg
/usr/bin/mrtg /etc/mrtg/httpd.cfg
/usr/bin/mrtg /etc/mrtg/mrtg.cfg
*エラーが出てアクセスできない [#yb60003e]
RPM形式でApacheをインストールしていて、mrtgを /var/www/html/mrtg とした場合、Forbiddenになります。
これは /etc/httpd/conf.d/ 以下に mrtg.conf が出来ていてAliasを張られているからです。コメントアウトしましょう。
*トラフィックが取れない [#x6394e8b]
まれにNICの認識が違うことがあるようで値が取れない場合があるみたいです。~
調べる場合は
$ snmpwalk -c public -v 1 localhost ipAdEntIfIndex
IP-MIB::ipAdEntIfIndex.127.0.0.1 = INTEGER: 1
IP-MIB::ipAdEntIfIndex.192.168.0.2 = INTEGER: 3
通常監視したいNICは2ですが、3だったりします。~
それぞれIN,OUT値を調べ、値を取得できることを確認し、cfgファイルに設定します。
$ snmpwalk -c public -v 1 localhost ifInOctets.3
$ snmpwalk -c public -v 1 localhost ifOutOctets.3
Target[index]: ifInOctets.3&ifOutOctets.3:public@localhost