2013-08-22

MRTG---cfgmaker的用法

最近 mrtg 的 server 掛了,所以要再找一台電腦重架

用 centos 6.4 x64 來裝…使用 yum 安裝 mrtg net-snmp net-snmp-utils

mrtg 在安裝當下的版本是 2.16.2-7

就以比較直接的做法就是…

/usr/bin/cfgmaker public@localhost --output=localhost.cfg
cfgmaker 是 mrtg 做某設備 run 網頁跟圖形的 config 產出器…其指令很豐富,可以用『man cfgmaker』來看…如上述的指令,其意思如下:
cfgmaker [snmp 的 comm]@[被偵測的 ip ]  --output==[ config 的產出路徑與檔名設定]
[snmp 的 comm]就是設備上 snmp 服務會被設定一個溝通器(或交涉名字,把這個跟現在聊天軟體用的id想成一塊就容易了解了)…此溝通器有分 RO(ReadOnly) 跟 RW(ReadWrite) ,只能讀取/可讀取也可更改資料…不特別指定的話,會自動用 public@x.x.x.x 的方式送出詢問…

然後要讓他跑出圖來就是
env LANG=C /usr/bin/mrtg localhost.cfg



上述是簡單的用法…(想要做首頁就用 indexmaker --output=index.html localhost.cfg ,但我沒有想要首頁,只要各偵測點的 interface 圖就好)

接下來因為自己的一些習慣,所以會想要更動一些作用…

上述基本的作法…你打開 localhost.cfg(產出後的 config 檔),你會發現一種格式…
### Interface 11001 >> Descr: 'Management-Port' | Name: 'Management' | Ip: '' | Eth: '' ###
Target[localhost_11001]: 11001:public@localhost:::::2
noHC[localhost_11001]: yes
SetEnv[localhost_11001]: MRTG_INT_IP="" MRTG_INT_DESCR="Management-Port"
MaxBytes[localhost_11001]: 15625000
Title[localhost_11001]: Traffic Analysis for 11001 -- localhost
### Interface 1000001 >> Descr: 'VirtualRouter0' | Name: 'VirtualRouter0' | Ip: '' | Eth: '' ###
### The following interface is commented out because:
### * filter specified by --if-filter rejected the interface
#
# Target[localhost_1000001]: 1000001:public@localhost:::::2
# noHC[localhost_1000001]: yes
# SetEnv[localhost_1000001]: MRTG_INT_IP="" MRTG_INT_DESCR="VirtualRouter0"
# MaxBytes[localhost_1000001]: 15625000
# Title[localhost_1000001]: Traffic Analysis for 1000001 -- localhost

依上述資料可以發現有兩個東西在同一台設備上被偵測 ,但只有「Management-Port」被做出 log、png 跟 html ,「VirtualRouter0」卻沒有被做出來…(上述「」中的只是一個代表,請想成是 interface FastEthernet port)

主要原因是因為, mrtg 預設會對 interface admin status down 的接口做 remark 的動作,就是從『Target[xxxx]』開始,每一行開頭都有個「#」…這個「#」就是告訴 mrtg 在做圖時不要執行這一行的意思…

但事實上,我們在偵測設備上的埠,其實每一個埠都要測,因為你不曉得這一個埠何時才會有人用,所以也是要加入偵測的行列中…這時候,就要告訴「cfgmaker」在做 config 前,就算是 admin status 是 down 的狀態的我也要偵測…

這時,你的 cfgmaker 可以改成這樣…
cfgmaker --zero-speed=12500000 --show-op-down public@localhost --output=localhost.cfg
你會看到我多加了「--zero-speed=12500000」跟「--show-op-down」在前面…這就是告訴 cfgmaker ,我要「show operater down」… operater 跟 admin 一樣的…
但使用「--show-op-down」一定要跟「--zero-speed=?」一起使用,「--zero-speed」的用意是告訴mrtg,如果在遇到目前剛好沒人使用的埠時,在「MaxBytes」的區塊上就補上「?」的值…比如我給的是 12500000 ,就是等於 12.5 MBytes ,這是速度,而轉換成速率就是 100Mb/s …因為 MaxBytes 不能為 0 …如果是 0 … mrtg 不會畫圖,所以用使「--show-op-down」不配個「--zero-speed」的話,那個「#」是不會拿掉的…

接下來是進階一點…

有時候我們偵測網路設備,會發現,它的 config 中除了會有 interface FastEthernet/gigaEthernet 之類的實際孔,還會有 vlan 啦… console 的…但我們其實不需要偵測 vlan 或 console 的流量(我只是比如說)…那如果我們沿用上面的「--zero-speed=12500000 --show-op-down」的話,這一些 vlan 啦、 console 的也會被做出圖啦…但實際上我們不要…

這時候就要改用下面的方式來告訴 cfgmaker 在抓資料做 config 時,要把 vlan 給「#」起來不用…
cfgmaker --zero-speed=125000000 --show-op-down --if-filter='$if_type!=53 and $if_type!=135 and $if_type!=136 and $if_type!=137' public@localhost --output=localhost.cfg
「--if-filter」是過濾器,「=」後的要用字串包起來,是判斷式…
比如上述的我用「--if-filter='$if_type!=53 and .....'」,這代表除了 if_type 是 53 跟 135~137 以外的我都要偵測,所以 if_type 等於 53 的就會被「#」起來…(iftype 是 cisco-ccna 的標準,可以上 cisco網站 查詢) ,而 53 所代表的就是「propVirtual」,就是虛擬物, vlan 就是被虛擬出來的一個 lan 的裝置,還有 135~137 是 cisco 上的 vlan ,那這指令的結果就是會看到 vlan 的都會被「#」…

底下是我常用的方式
/usr/bin/cfgmaker --snmp-options=:::::2 --global "WorkDir: /var/www/mrtg/" --global "AbsMax[_]: 25000000" --global "Unscaled[_]: ym" --global "XSize[_]: 600" --global "YSize[_]: 150" --global "YTics[_]: 10" --zero-speed=125000000 --show-op-down --if-filter='$if_type!=1 and $if_type!=53 and $if_type!=24 and $if_type!=135 and $if_type!=136 and $if_type!=137 and $if_type!=142 and $if_type!=217 and $if_type!=218 and $if_type!=222 and $if_type!=223' public@localhost --output=localhost.cfg
這一段是再告訴 mrtg 抓資料時要用 snmpv2 來抓,因為 v2 是跑 64bits ,上限值比較大,傳統是跑 v1 , 32bits ,當流速超過 100Mb/s 時會有斷掉的問題…(因為超過值之後會從零開始算)

這一段是告訴 mrtg 在產出 png 、 log 、 html 要放的位置…

這一段是告訴 cfgmaker ,請把「#」加在 vlan 跟 loopback 上…請注意此段單引號放的位置是『 '--if-filter=$if_type!=53 and ......... '』而不是『--if-filter='$if_type!=53 and ....'』,而且,只能用單引號,不要用雙引號,會有問題…還有,多條件請用『and 或 or』,不要用『&& 或 ||』…以前的版本好像可以,但在我這個版本我用『&& 或 ||』會出錯

沒有留言: