net-snmp, mrtgをyumでインストール

# yum install net-snmp
# yum install net-snmp-utils
# yum install mrtg

net-snmpのセットアップ

# 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
# /etc/rc.d/init.d/snmpd stop
# /etc/rc.d/init.d/snmpd start

確認
すらずらっとデータが出力されればOK

# snmpwalk -c public -v 1 localhost .1

トラフィック確認設定

# vi /etc/mrtg/traffic.cfg
WorkDir: /home/user/public_html/mrtg
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確認設定

# 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

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>

メモリ確認設定

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[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>

ディスク容量確認設定

# 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

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プロセス確認設定

# 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

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>

自動起動の設定

# 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

エラーが出てアクセスできない

RPM形式でApacheをインストールしていて、mrtgを /var/www/html/mrtg とした場合、Forbiddenになります。

これは /etc/httpd/conf.d/ 以下に mrtg.conf が出来ていてAliasを張られているからです。コメントアウトしましょう。

トラフィックが取れない

まれに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

トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS