網路流量 Network Traffic
 
Fedora core
 
設定 SNMP
[1.] 套件安裝

      apt-get install  mrtg net-snmp net-snmp-utils


[2.] vi /etc/snmp/snmp.conf

rocommunity      10.1.1.0/24              cross
# —————–允許誰可存取—— community

[3.] 啟動 SNMP

      service snmpd start

 

設定 MRTG

[1.] mrtg預設目錄 /var/www/mrtg/

      如果需要設定網路流量、cpu、ram等MRTG,在mrtg中建立各自的目錄,
      mkdir /var/www/mrtg/net /var/www/mrtg/cpu等等
      也可以考慮mrtg.cfg的"Directory[ ]: dirname"參數
 
[2.] 製作 cfg檔
      cfgmaker –output=/etc/mrtg/mrtg-net.cfg  [email protected]

或者
      cfgmaker [email protected] > /etc/mrtg/mrtg-net.cfg

[3.] 如果未自行加入任何參數項目,則需修改設定檔
      vi /etc/mrtg/mrtg-net.cfg

WorkDir: /var/www/mrtg/net/  # mrtg圖檔放置目錄
Option[_]: growright, bits        # 測網路流量的參數
Language: big5                       # 產生的網頁為big5

      或者同時把三台將被偵測的機器寫在同一個設定檔裡
         cfgmaker [email protected] [email protected] [email protected] > mrtg-net.cfg

      或者利用 –global參數,可及時設定該要修改的config,不用再到cfg檔作更改全域設定
         cfgmaker –global "WorkDir: /var/www/mrtg"
                         –global "Options[_]: growright,bits"
                         –global "Language: big5"
                         [email protected]
                         > mrtg_net.cfg

       或者針對 domain name,這也有利於浮動的ADSL
         cfgmaker –global "WorkDir: /var/www/mrtg"
                         –global "Options[_]: growright,bits"
                         –global "Language: big5"
                         [email protected]
                         > mrtg_net.cfg

       或者分開設定,每個 cross@ip以在它上方的設定為基準
         cfgmaker –global "WorkDir: /var/www/mrtg"
                         –global "Options[_]: growright,bits"
                         –global "Language: big5"
                         –ifdesc=nr
                         [email protected]
                         –global "Options[_]: growright"            
                         –ifdesc=ip
                         [email protected]
                         > mrtg_net.cfg

      或者 community與 ip分開
         cfgmaker –global "WorkDir: /var/www/mrtg"
                         –global "Options[_]: growright,bits"
                         –global "Language: big5"
                         –community=cross
                         10.1.1.1
                         10.1.1.3
                         > mrtg_net.cfg

       或者用 –dns-domain參數後,cross@後面只要接domainname前面的名稱即可
         cfgmaker –global "WorkDir: /var/www/mrtg"
                         –global "Options[_]: growright,bits"
                         –global "Language: big5"
                         –dns-domain=ssorc.tw
                         –community=cross
                         wn
                         ws
                         > mrtg_net.cfg

[4.] 執行mrtg
      mrtg /var/www/mrtg/net/mrtg-net.cfg
 
      這個動作要執行三次,即可正常
      若有問題的話,就需要改 mrtg-net.cfg ,直到沒有錯誤發生為止
      或事先使用–check參數,check其cfg檔正確與否
      但前提要在 LANG=C的環境下,作法如下
      env LANG=C mrtg mrtg-net.cfg
      不過 mrtg也會提示你

[5.] 製作首頁index.html
      indexmaker –output=/var/www/mrtg/net/index.html –title='流量統計' /var/www/mrtg/net/mrtg-net.cfg

      indexmaker mrtg-net.cfg > index.html

      標題為cross,整頁以一欄排列顯示
      indexmaker –title cross –columns 1 mrtg_net.cfg > /var/www/mrtg/index.html

      個人習慣
      indexmaker /etc/mrtg/mrtg.cfg-net –sectionhost –section description   –title='SSORC.TW – Network Traffic' > /var/www/mrtg/net/index.html

      或者
      cfgmaker –global "WorkDir: /var/www/mrtg/net" –global "Options[_]: growright, bits" –ifdesc=descr –community=cross localhost 10.1.1.3 10.1.1.1 > /etc/mrtg/mrtg.cfg-net
      indexmaker /etc/mrtg/mrtg.cfg-net   –title='SSORC.TW – Network Traffic' >  /var/www/mrtg/net/index.html

[6.] 如果不作daemon mode,就使用排程方式執行mrtg
       每五分鐘執行一次
       vi /etc/crontab

*/5 * * * * root env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg-net.cfg > /dev/null 2>&1

      如果偵測多台主機時,最好寫個script檔來讓它依序執行較好,效率應該會比多個同時mrtg來的好

      或將設定寫入同一cfg檔裡

 

cfgmaker 的參數

–ifref=nr                   # interface references by Interface Number (default)
–ifref=ip                    # … by Ip Address
–ifref=eth                   # … by Ethernet Number
–ifref=descr               # … by Interface Description
–ifref=name               #        … by Interface Name
–ifref=type                 # … by Interface Type
–ifdesc=nr                 # interface description uses Interface Number (default)
–ifdesc=ip                  # … uses Ip Address
–ifdesc=eth                  # … uses Ethernet Number
–ifdesc=descr              # … uses Interface Description
–ifdesc=name             # … uses Interface Name
–ifdesc=catname         # … uses CatOS Interface Name
–ifdesc=alias               # … uses Interface Alias
–ifdesc=type               # … uses Interface Type

mrtg.cfg 參數

# Global Option –
Refresh: 300                     # 更新網頁的時間,預設為300秒
Interval: 5                         # 多久時間 call mrtg一次,預設為5分鐘,且至少也要5分鐘
RunAsDaemon: Yes         # daemon mode
                                         # 當執行 /usr/bin/mrtg /etc/mrtg/mrtg.cfg後,以cfg檔中的
                                         # RunAsDaemon: Yes 與 Interval: 5 設定每五分鐘作背景運作
# Target Option –
RouterUptime[10.1.1.254_cpu]: [email protected]      # 算出系統已運作多久時間,顯示於網頁上方
RouterName[10.1.1.254_cpu]:                                 # ? 測試中
MaxBytes[10.1.1.254_cpu]: 1250000                      # Bytes
MaxBytes1[10.1.1.254_cpu]:                                   # 與MaxBytes相同,此為變數1
MaxBytes2[10.1.1.254_cpu]:                                   # 與MaxBytes相同,此為變數2

PageFoot[10.1.1.254_cpu]: Contact <A href="mailto:[email protected]">Cross</A>                                    # 顯示於網頁下方
BodyTag[10.1.1.254_cpu]: <BODY LEFTMARGIN="1" TOPMARGIN="1" BACKGROUND="picture.gif">     # 修改網頁<body>的部份

AbsMax[10.1.1.254_cpu]: 2500000    # 如果流量會超過MaxBytes所設定的值,必設定此絕對大值,否則超過的會被忽略
Unscaled[10.1.1.254_cpu]: dwmy       # 改垂直刻度,依據MaxBytes的值,d=day、w=week、m=month、y=year
WithPeak[10.1.1.254_cpu]: wmy        # 一般圖型只顯示平均值,此設定可於week、month、及year的圖顯示巔峰值,w=week、m=month、y=year

Directory[10.1.1.254_cpu]: 10.1.1.254_cpu  # 當WorkDir設定為/var/www/mrtg/cpu時,
                                                                       # 此設定會於這目錄下再產生一10.1.1.254_cpu名稱的目錄,將圖檔放在這
XSize[10.1.1.254_cpu]: 100
# 與
YSize[10.1.1.254_cpu]: 400                          # 圖型預設像素為100×400,此設定可更改顯示像素,XSize值介於20~600之間,YSize必須大於20

XZone[10.1.1.254_cpu]: 2.0
# 與
YZone[10.1.1.254_cpu]: 2.0                          # 將圖放大或縮小

XScale[10.1.1.254_cpu]: 1.5
# 與
YScale[10.1.1.254_cpu]: 1.5                         # 設定刻度

YTics[10.1.1.254_cpu]: 4                              # 預設YLegend[]:顯示只有四線,此設定可設定顯示多少線
# 與
YTicsFactor[10.1.1.254_cpu]: 1.0                 # 預設刻度為1,此設定線與線之間是多少刻度

PNGTitle[10.1.1.254_cpu]: wow                   # 於"圖中的上方"設定字串

Options[10.1.1.254_cpu]: growright, bits                         # 用在網路流量
# 或
Options[10.1.1.254_cpu]: growright, nopercent, gauge    # 用在 CPU 負載
 
                                         growright                                 # 將資料隨時間變化的順序以右而左繪圖
                                         bits                                           # 資料單位為 bits
                                         nopercent                                 # 在圖下方的說明文字中,不顯示百分比
                                         gauge                                       # 圖表的上限固定
                                         absolute                                    # 配合 gauge使用以純化所搜集到的資料

                                         integer                                      # 顯示整數,不要有小數點
                                         dorelpercent                             # 額外顯示計算IN流量to Out流量的相對百分比,當In流量大於 OUT流量
                                         avgpeak                                   # 平均值計算,以該統計圖所使用的時間單位為基本資料

                                         printrouter                                # 與PNGTitle[10.1.1.254_cpu]: wow呈現的地方一樣,但此設定是顯示10.1.1.254_cpu
                                         pngdate                                    # 與printrouter呈現的地方一樣,但顯示時間timestamp

Background[10.1.1.254_cpu]: #a0a0a0a                                                                                                    # 設定背景顏色
Colours[10.1.1.254_cpu]: GREEN#00eb0c,BLUE#1000ff,DARK GREEN#006600,VIOLET#ff00ff        # 改變 In與Out的地方的顏色

YLegend[]: Bits per Second                                     # 預設資訊
ShortLegend[]: b/s
Legend1[]: Incoming Traffic in Bits per Second
Legend2[]: Outgoing Traffic in Bits per Second
Legend3[]: Maximal 5 Minute Incoming Traffic
Legend4[]: Maximal 5 Minute Outgoing Traffic
LegendI[]: &nbsp;In:
LegendO[]: &nbsp;Out:

Timezone[]: Taiwan                                 # 區域時間
TimeStrPos[]: RU                                     # timestamp在那個角落顯示,RU=RightUpper、LU=LeftUpper、RL=RightLower、LL=LeftLower
TimeStrFmt[]: %Y-%m-%d %H:%M       # timestamp預設為%Y-%m-%d %H:%M的格式

ThreshDir: /var/mrtg/thresh
ThreshMinI[]: 80                                                                              # In的流量小於80,執行mrtgalert
ThreshMaxI[]: 800000                                                                     # In的流量大於800000,執行mrtgalert
ThreshDesc[]:                                                                                  # 指定mrtgalert的環境變數
ThreshProgI[]: /var/www/mrtg/thresh/scripts/mrtgalert                    # 執行script
ThreshProgOKI[]: ?                                                                         # 值尚不知怎麼設,只知這參數是base on ThreshMinI and ThreshMaxI
SetEnv[]: EMAIL="[email protected]" HOST="ssorc.tw"     # 如果script不完全寫在mrtgalert,亦可定義在此

mrtg執行檔參數

–user mrtg                               # unix 使用者
–group mrtg                            # unix 群組
–daemon                                 # 當背景模式,預設5min運作一次mrtg,
                                                # 可於cfg檔中設定Interval參數作幾時間後運作一次mrtg,
                                                # 如果不用–daemon參數,可用cfg檔中的RunAsDaemon參數


–pid-file=/var/run/mrtg.pid      # 如果不設定路徑,會與cfg檔同目錄產生pid檔
–logging /var/log/mrtg.log
–check                                     # 只作檢測cfg的設定正確與否,不作輸出的動作

 indexmaker參數

–width                                                                          # 設定寬度
–height                                                                         # 設定高度
–sort [ title | name | descr | original ]                             # 依據排版
–show [ day | week | month | year | none ]                    # 在index.htm首頁依據顯示
–section [ h1 | title | name | description | portname ]     # 在每圖表左上角依據顯示
–sectionhost                                                                 # 在每圖表左上角依據顯示前面附加hostname,
                                                                                     # 但如果Target是以mathematial expression數學表示,則無效
–title cross                                                                    # 首頁標題為 cross
–columns 1                                                                  # 整頁以一欄排列

 圖檔說明

 

 

ref: http://www.enterastream.com/whitepapers/mrtg/mrtg-manual-cap9.html#p93

http://redhat.ecenter.idv.tw/bbs/showthread.php?s=98d3d7990a7dc71926ac98477c24f110&threadid=43276

http://phorum.study-area.org/viewtopic.php?t=18410&highlight=mrtg

http://phorum.study-area.org/viewtopic.php?t=21106&highlight=mrtg

 

Related posts 相關文章
使用 Grafana 與 Prometheus 監控主機
More...
nagios 使用 pnp4nagios 畫 rrdtool 圖,像 MRTG 圖表
More...
我們一步一步的被監控著,IPHONE 5S的指紋是否會被 NSA 用去
More...
RRDTOOL 的 RRD 檔一些小心得,關於存的筆數
More...

作者

留言

撰寫回覆或留言

發佈留言必須填寫的電子郵件地址不會公開。