[FreeBSD] MRTG - 偵測流量、CPU Load、RAM Usage

| 元月 13, 2007 | 2個迴響| 沒有引用| 6949 reads | Size: L, M, S | Edit: P, C, R |
| Category: Unix-like, Server. |

    主要是參考「OHaHa's 學習心得」,紀錄一下自己弄的。

    1. SNMP

    1.1 安裝

    # cd /usr/ports/net-mgmt/net-snmp
    # make install clean

    1.2 設定 snmpd.conf

    /usr/local/share/snmp 新增一個 snmpd.conf,內容是:

    rocommunity mrtg

    1.3 重新啟動 snmpd

    # /usr/local/etc/rc.d/snmpd restart

    2. MRTG :: 流量

    2.1 安裝:

    # cd /usr/ports/net-mgmt/mrtg
    # make install clean

    2.2 設定:

    # mkdir /usr/local/www/data/mrtg
    # mkdir /usr/local/www/data/mrtg/www
    # cfgmaker  --global 'WorkDir: /usr/local/www/data/mrtg/www'  --global 'Options[_]: growright, bits'  --global 'Language: big5'  --global 'WithPeak[_]: wmy'  mrtg@localhost  >  /usr/local/www/data/mrtg/www/www.cfg

    接著執行看看:

    # mrtg /usr/local/www/data/mrtg/www/www.cfg

    跑的三次左右,到沒有警告為止,沒有問題就可以丟進 crontab 去跑了。

    如果需要 index.html,可以用:

    # indexmaker  --title 'MRTG'  --addhead='<meta http-equiv="Content-Type" content="text/html; charset=big5">'  --output /usr/local/www/data/mrtg/www/index.html  --columns=1  --nolegend   /usr/local/www/data/mrtg/www/www.cfg

    這樣就完成了。 

    3. MRTG :: CPU Load

    使用者、系統的 CPU Load。 

    3.1 設定:

    首先:

    # mkdir /usr/local/www/data/mrtg/cpu

    在 /usr/local/www/data/mrtg/cpu 下, 建立一個 cpu.cfg,內容是:

    LoadMIBs: /usr/local/share/snmp/mibs/UCD-SNMP-MIB.txt
    Target[cpu]: ssCpuRawUser.0&ssCpuRawSystem.0:mrtg@localhost
    RouterUptime[cpu]: mrtg@localhost

    Title[cpu]: CPU Load
    PageTop[cpu]: <H1>CPU Load (user and system)</H1>
    MaxBytes[cpu]: 100
    Language: big5
    WorkDir: /usr/local/www/data/mrtg/cpu
    WithPeak[_]: wmy
    Options[cpu]: growright,nopercent

    ShortLegend[cpu]: %
    YLegend[cpu]: CPU Utilization
    Legend1[cpu]: User CPU Load (%)
    Legend2[cpu]: System CPU Load (%)
    LegendI[cpu]: User Load
    LegendO[cpu]: System Load

    接著測試看看:

    mrtg /usr/local/www/data/mrtg/cpu/cpu.cfg

    一樣跑個三四次到沒有警告為止,沒問題就可以丟進 crontab。

    如果要 index.html:

    # indexmaker  --title 'CPU Load'  --addhead='<meta http-equiv="Content-Type" content="text/html; charset=big5">'  --output /usr/local/www/data/mrtg/cpu/index.html  --columns=1  --nolegend  /usr/local/www/data/mrtg/cpu/cpu.cfg

    4. MRTG :: Memory Usage

    目前記憶體的剩餘狀況。

    首先建立資料夾:

    # mkdir /usr/local/www/data/mrtg/memory

    在 /usr/local/www/data/mrtg/memory 下, 建立一個 memory.cfg,內容是:

    LoadMIBs: /usr/local/share/snmp/mibs/UCD-SNMP-MIB.txt
    Target[memory]: memAvailReal.0&memAvailSwap.0:mrtg@localhost
    Title[memory]: RAM Usage

    PageTop[memory]: <h1>RAM Usage</h1>
    MaxBytes[memory]: 1000000000
    kMG[memory]: k,M,G,T,P,X
    Language: big5
    WorkDir: /usr/local/www/data/mrtg/memory
    WithPeak[_]: wmy
    Options[memory]: nopercent,growright,gauge,noinfo

    ShortLegend[memory]: (in Octets)
    Ylegend[memory]: RAM Usage
    Legend1[memory]: RAM Avail
    Legend2[memory]: Swap Avail
    LegendI[memory]: RAM Avail
    LegendO[memory]: Swap Avail

    接著測試看看:

    mrtg /usr/local/www/data/mrtg/memory/memory.cfg

    一樣跑個三四次到沒有警告為止,沒問題就可以丟進 crontab。

    如果要 index.html:

    # indexmaker  --title 'Memory Usage'  --addhead='<meta http-equiv="Content-Type" content="text/html; charset=big5">'  --output /usr/local/www/data/mrtg/memory/index.html  --columns=1  --nolegend  /usr/local/www/data/mrtg/memory/memory.cfg

    這樣就完成了。 


    隨機文章:
    » [FreeBSD] MRTG
    » [FreeBSD] SNMP and MRTG on FreeBSD 7
    » [FreeBSD] Apache, MySQL, PHP
    » Lifetype 1.1 Release
    » 虛擬主機


Leave A Comment:













   


2 迴響 of "[FreeBSD] MRTG - 偵測流量、CPU Load、RAM Usage"

XingRe: [FreeBSD] MRTG - 偵測流量、CPU Load、RAM Usage By Xing @ 2007 十二月 12, 18:41 :

非常感謝您發表的文章,對於初學FreeBSD的我,相當有幫助,依照您的設定,我也成功的設定完成了!特此感謝!還希望您多發表

ajer001Re: [FreeBSD] MRTG - 偵測流量、CPU Load、RAM Usage By ajer001 @ 2007 十二月 15, 22:50 :

@Xing
很高興能幫上忙 :D