[FreeBSD] SNMP 統計流量分析 mrtg
Mar 20th, 2008 by appleboy 參觀者:4,649Views 機器人:531Views
最近處理系上伺服器,安裝的是 FreeBSD 7.0 Release 版本,想說來裝個 mrtg 來統計流量,因為目前 SNMP 已經納入 FreeBSD base 系統裡面了,所以在安裝 mrtg 就相當方便了,我之前有寫過三篇關於統計流量的教學
MRTG Server performace
[Linux] Mrtg 實做 war3 線上人數統計
[FreeBSD] 安裝基本mrtg主機流量統計圖
[FC4] snmpd + mrtg 安裝教學「注意事項」
上面這幾篇看完,大概也就會基本的 mrtg 畫圖了,只不過我在 FreeBSD 上有遇到一個問題:
首先我們先要開啟 /etc/rc.conf,加入 bsnmp 服務
bsnmpd_enable="YES"
第一次啟動時可以手動跑:
在啟動的時候遇到下面問題
Mar 20 23:10:01 www snmpd[67795]: foobar: hostname nor servname provided, or not known
Mar 20 23:10:01 www snmpd[67795]: in file /etc/snmpd.config line 46
Mar 20 23:10:01 www snmpd[67795]: error in config file
後來解決方式呢,就是打開 snmpd 的設定檔/etc/snmpd.config
把
host := foobar
改成
#改成自己的機器 domain
host := www.xxx.ccu.edu.tw
這樣就解決了,不過我去比對了一下 FreeBSD 6.3 跟 7.0 版本,發現
7.0 release :
# open standard SNMP ports
begemotSnmpdPortStatus.0.0.0.0.161 = 1
6.3 release :
# open standard SNMP ports
begemotSnmpdPortStatus.[$(host)].161 = 1
begemotSnmpdPortStatus.127.0.0.1.161 = 1
6.3 多了那一行,我也不知道做什麼用的
解答:感謝 JoeHorn
begemotSnmpdPortStatus.0.0.0.0.161 = 1
把 161 port 開在 *.* ,像這樣:
root bsnmpd 803 6 udp4 *:161 *:*: 6.3 release :
: # open standard SNMP ports
: begemotSnmpdPortStatus.[$(host)].161 = 1
: begemotSnmpdPortStatus.127.0.0.1.161 = 1
把 161 port 開在特定 IP 與 localhost , ex:root bsnmpd 677 6 udp4 111.222.333.444:161 *:*
root bsnmpd 677 7 udp4 127.0.0.1:161 *:*
然後裝 net-mgmt/mrtg:
make install clean
加入 /etc/rc.conf 檔案
mrtg_daemon_enable="YES"
裝完後跑 cfgmaker 產生檔案:
在 cfg 檔案裡面加入
RunAsDaemon:Yes
Interval:5
Refresh:300
這樣的話,比較不會吃系統資源,不然如果利用 crontab 去每5分鐘跑一次的話,跑的瞬間會衝到 CPU 使用率 100%
然後修改 mrtg.cfg 內的 WorkDir,最後產生 index.html:
--width=500 \
--height=135 \
-title="NAS Server - 網路流量分析" \
-output="/var/www/html/mrtg/index.htm" \
/etc/mrtg/mrtg.cfg.local
最後在寫入開機程序 /etc/rc.local
/usr/bin/env LANG=C /usr/local/bin/mrtg /usr/local/etc/mrtg/mrtg.cfg
這樣以後開機就會自動執行了
參考資料:
gslin 大大:FreeBSD 上的 SNMP
Related View

[...] FreeBSD 7.1 Release 要裝起 SNMP 搭配 MRTG 已經非常容易,請參考之前寫的教學:[FreeBSD] SNMP 統計流量分析 mrtg ,可是這次因為安裝新系統,使用 Perl 5.8.9 在 MRTG [...]