茫茫網海中的冷日 - 對這文章發表回應
茫茫網海中的冷日
         
茫茫網海中的冷日
發生過的事,不可能遺忘,只是想不起來而已!
 恭喜您是本站第 1729824 位訪客!  登入  | 註冊
主選單

Google 自訂搜尋

Goole 廣告

隨機相片
IMG_60D_00047.jpg

授權條款

使用者登入
使用者名稱:

密碼:


忘了密碼?

現在就註冊!

對這文章發表回應

發表限制: 非會員 可以發表

發表者: 冷日 發表時間: 2005/2/17 6:49:14
[mini-HOWTO] SNMP & MRTG made in easy (Power Under Control; )

所需的東西:
* [net-analyzer/net-snmp]
* [media-libs/libgd]
* [net-analyzer/mrtg]
* [sys-apps/dcron]
這兩個可以選一個來用:
* [net-www/mini_httpd] or [net-www/apache]
警告:不要將開頭為下面所示的指令欄內容剪下貼上。

/bin/cat -s > /foo/bar



例: http://www.orson.it/stat
0) 切換使用者

/bin/su -



請鍵入您的密碼。
1) 起步

/usr/bin/mkdir /etc/mrtg
/usr/bin/mkdir /etc/cron.mrtg
/usr/bin/mkdir /var/www/localhost/mrtg
 


2) 編輯

/bin/cat -s > /etc/snmp/snmpd.conf

com2sec local    127.0.0.1/32    public
com2sec local    10.10.10.0/24   public

group MyROGroup v1         local
group MyROGroup v2c        local
group MyROGroup usm        local

view  all   included  .1  80

access MyROGroup ""  any   noauth   exact  all   none   none

syslocation MyLocation
syscontact Me <me@somewhere.org>


接著按下 [ctrl+d]。

編輯 /etc/conf.d/snmpd 檔,並且加上:

-c /etc/snmp/snmpd.conf



到 SNMPD_FLAGS 那一行
(類似這樣:SNMPD_FLAGS="-c /etc/snmp/snmpd.conf")

3) 服務程式

/etc/init.d/snmpd start
/sbin/rc-update add snmpd default
 


4) 設定

流量:

/usr/bin/cfgmaker
--output=/etc/mrtg/traffic.cfg
--ifdesc=ip
--ifref=descr
--global "WorkDir: /var/www/localhost/mrtg"
--global "Options[_]: bits,growright"
public@localhost


Cpu:

/bin/cat -s > /etc/mrtg/cpu.cfg
WorkDir: /var/www/localhost/mrtg
LoadMIBs: /usr/share/snmp/mibs/UCD-SNMP-MIB.txt
Target[localhost.cpu]:ssCpuRawUser.0&ssCpuRawUser.0:public@localhost + ssCpuRawSystem.0&ssCpuRawSystem.
0:public@localhost + ssCpuRawNice.0&ssCpuRawNice.0:public@localhost
RouterUptime[localhost.cpu]: public@localhost
MaxBytes[localhost.cpu]: 100
Title[localhost.cpu]: CPU Load
PageTop[localhost.cpu]: 活動中的 CPU 負載 %
Unscaled[localhost.cpu]: ymwd
ShortLegend[localhost.cpu]: %
YLegend[localhost.cpu]: CPU Utilization
Legend1[localhost.cpu]: Active CPU in % (Load)
Legend2[localhost.cpu]:
Legend3[localhost.cpu]:
Legend4[localhost.cpu]:
LegendI[localhost.cpu]:  Active
LegendO[localhost.cpu]:
Options[localhost.cpu]: growright,nopercent


現在請下 [ctrl+d].

Mem:

/bin/cat -s > /etc/mrtg/mem.cfg
LoadMIBs: /usr/share/snmp/mibs/HOST-RESOURCES-MIB.txt
Target[localhost.mem]: .1.3.6.1.4.1.2021.4.11.0&.1.3.6.1.4.1.2021.4.11.0:public@localhost
PageTop[localhost.mem]: <H1>Free Memory</H1>
WorkDir: /var/www/localhost/mrtg
Options[localhost.mem]: nopercent,growright,gauge,noinfo
Title[localhost.mem]: Free Memory
MaxBytes[localhost.mem]: 1000000
kMG[localhost.mem]: k,M,G,T,P,X
YLegend[localhost.mem]: bytes
ShortLegend[localhost.mem]: bytes
LegendI[localhost.mem]:  Free Memory:
LegendO[localhost.mem]:
Legend1[localhost.mem]: Free memory, not including swap, in bytes


現在按 [ctrl+d]

Swap:

/bin/cat -s > /etc/mrtg/swap.cfg
LoadMIBs: /usr/share/snmp/mibs/UCD-SNMP-MIB.txt
Target[localhost.swap]: memAvailSwap.0&memAvailSwap.0:public@localhost
PageTop[localhost.swap]: <H1>Swap Memory</H1>
WorkDir: /var/www/localhost/mrtg
Options[localhost.swap]: nopercent,growright,gauge,noinfo
Title[localhost.swap]: Free Memory
MaxBytes[localhost.swap]: 1000000
kMG[localhost.swap]: k,M,G,T,P,X
YLegend[localhost.swap]: bytes
ShortLegend[localhost.swap]: bytes
LegendI[localhost.swap]:  Free Memory:
LegendO[localhost.swap]:
Legend1[localhost.swap]: Swap memory avail, in bytes


現在按 [ctrl+d]

Ping:

/bin/cat -s > /etc/mrtg/ping.cfg
WorkDir: /var/www/localhost/mrtg
Title[localhost.ping]: Round Trip Time
PageTop[localhost.ping]: <H1>Round Trip Time</H1>
Target[localhost.ping]: `/etc/mrtg/ping.sh`
MaxBytes[localhost.ping]: 2000
Options[localhost.ping]: growright,unknaszero,nopercent,gauge
LegendI[localhost.ping]: Pkt loss %
LegendO[localhost.ping]: Avg RTT
Legend1[localhost.ping]: Maximum Round Trip Time in ms
Legend2[localhost.ping]: Minimum Round Trip Time in ms
Legend3[localhost.ping]: Maximal 5 Minute Maximum Round Trip Time in ms
Legend4[localhost.ping]: Maximal 5 Minute Minimum Round Trip Time in ms
YLegend[localhost.ping]: RTT (ms)


現在按 [ctrl+d]

5) 產生工作

Traffic:

/bin/cat -s > /etc/cron.mrtg/traffic.sh
#!/bin/sh
/usr/bin/mrtg /etc/mrtg/traffic.cfg


現在按 [ctrl+d]

Cpu:

/bin/cat -s > /etc/cron.mrtg/cpu.sh
#!/bin/sh
/usr/bin/mrtg /etc/mrtg/cpu.cfg


現在按 [ctrl+d]

Mem:

/bin/cat -s > /etc/cron.mrtg/mem.sh
#!/bin/sh
/usr/bin/mrtg /etc/mrtg/mem.cfg


現在按 [ctrl+d]

Swap:

/bin/cat -s > /etc/cron.mrtg/swap.sh
#!/bin/sh
/usr/bin/mrtg /etc/mrtg/swap.cfg


現在按 [ctrl+d]

Ping:

/bin/cat -s > /etc/cron.mrtg/ping.sh
#!/bin/sh
/usr/bin/mrtg /etc/mrtg/ping.cfg


現在按 [ctrl+d]

ping.sh

/bin/cat -s > /etc/mrtg/ping.sh
#!/bin/sh
PING="/bin/ping"
# Google, for example
ADDR="google.com"
DATA=`$PING -c10 -s500 $ADDR -q `
LOSS=`echo $DATA | awk '{print $18 }' | tr -d %`
echo $LOSS
if [ $LOSS = 100 ]
then
               echo 0
else
        echo $DATA | awk -F/ '{print $5 }'
fi


現在按 [ctrl+d]

/bin/chmod +x /etc/cron.mrtg/*.sh
/bin/chmod +x /etc/mrtg/ping.sh


執行每個指令稿三次(不需理會警告)

/etc/cron.mrtg/traffic.sh
/etc/cron.mrtg/cpu.sh
/etc/cron.mrtg/mem.sh
/etc/cron.mrtg/swap.sh
/etc/cron.mrtg/ping.sh


6) 建立索引

/usr/bin/indexmaker --output=/var/www/localhost/mrtg/index.html
--title="Power Under Control :)"
--sort=name
--enumerate
/etc/mrtg/traffic.cfg
/etc/mrtg/cpu.cfg
/etc/mrtg/mem.cfg
/etc/mrtg/swap.cfg
/etc/mrtg/ping.cfg


7) 系統排程

/bin/cat >> /var/spool/cron/crontabs/root
*/5 * * * * /bin/run-parts /etc/cron.mrtg 1> /dev/null


按[Ctrl-D]。
(或是/usr/bin/crontab -e)

Power Under Control
開啟Mozilla(它是個好物),並瀏覽:

/var/www/localhost/www/index.html



(或用您的網頁伺服器)

http://localhost/mrtg

#給進階使用者#

對其他的目標(或是統計),試著使用其他的物件ID(OID)

*輪詢:

roberto@moira mrtg $ snmpwalk -v 1 -c public localhost mgmt.1.2.2.1.10.2
IF-MIB::ifInOctets.2 = Counter32: 140021440


*翻譯

roberto@moria mrtg $ snmptranslate -IR -Td mgmt.1.2.2.1.10.2
IF-MIB::ifInOctets.2
ifInOctets OBJECT-TYPE
  -- FROM       IF-MIB, RFC1213-MIB
  SYNTAX        Counter32
  MAX-ACCESS    read-only
  STATUS        current
  DESCRIPTION   "The total number of octets received on the interface,
            including framing characters.

            Discontinuities in the value of this counter can occur at
            re-initialization of the management system, and at other
            times as indicated by the value of
            ifCounterDiscontinuityTime."
::= { iso(1) org(3) dod(6) internet(1) mgmt(2) mib-2(1) interfaces(2) ifTable(2) ifEntry(1) ifInOctets(
10) 2 }


*最重要的檔案


/usr/share/doc/net-snmp
/usr/share/doc/mrtg-*/contrib

- man mrtg
- man snmpd
- man snmpwalk
- man crontab
- man cat


祝使用愉快:D
內容圖示
url email imgsrc image code quote
樣本
bold italic underline linethrough   












 [詳情...]
validation picture

注意事項:
預覽不需輸入認證碼,僅真正發送文章時才會檢查驗證碼。
認證碼有效期10分鐘,若輸入資料超過10分鐘,請您備份內容後,重新整理本頁並貼回您的內容,再輸入驗證碼送出。

選項

Powered by XOOPS 2.0 © 2001-2008 The XOOPS Project|