#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 *mrtg設定 [#v4934ee9] # vi /etc/mrtg/mrtg.cfg 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 # Traffic Target[traffic]: 2:public@localhost MaxBytes[traffic]: 1250000 Title[traffic]: Traffic Analysis PageTop[traffic]: <H1>Traffic Analysis</H1> # CPU 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> # 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/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