給Ubuntu伺服器安裝MRTG監視軟體

來源:互聯網
上載者:User

給Ubuntu伺服器安裝MRTG監視軟體:

一:安裝網路流量監視[預設5分鐘採集一次]

切換到超級使用者:
sudo -sH

安裝軟體:
apt-get install apache2
apt-get install mrtg
apt-get install snmpd

編輯snmpd:
vim /etc/snmp/snmpd.conf



尋找到類似的行,修改為如下所示:(僅僅修改屏蔽或放開)
# sec.name source community
# com2sec paranoid default public # kommentieren
com2sec readonly default public # <- auskommentieren
#com2sec readwrite default private

重啟snmpd服務:
/etc/init.d/snmpd restart

重建mrtg的設定檔:
cfgmaker public@localhost > /etc/mrtg.cfg

(注意)如果僅僅監視一個IP地址採用如下命令:
cfgmaker public@192.168.0.1 >> /etc/mrtg.cfg

產生mrtg的首頁:
indexmaker /etc/mrtg.cfg > /var/www/mrtg/index.html

訪問:
http://localhost/mrtg/

二安裝CPU負載監視[預設5分鐘採集一次]

切換到超級使用者:
sudo -sH

安裝軟體:
apt-get install sysstat

建立CPU指令碼:
mkdir /opt/mrtg
vim /opt/mrtg/mrtg.cpu
#!/bin/bash
cpuusr=`/usr/bin/sar -u 1 3 | grep Average | awk {print $3}`
cpusys=`/usr/bin/sar -u 1 3 | grep Average | awk {print $5}`
UPtime=`/usr/bin/uptime | awk {print $3""$4""$5}`
echo $cpuusr
echo $cpusys
echo $UPtime
hostname

使指令碼可以執行:
chmod +755 /opt/mrtg/mrtg.cpu

修改 /etc/mrtg.cfg 在檔案最後加入cpu項目
Target[cpu]: `/opt/mrtg/mrtg.cpu`
MaxBytes[cpu]: 100
Options[cpu]: gauge, nopercent, growright
YLegend[cpu]: CPU loading (%)
ShortLegend[cpu]: %
LegendO[cpu]:   CPU us;
LegendI[cpu]:   CPU sy;
Title[cpu]: CPU Loading
PageTop[cpu]: <H1>CPU Loading</H1>

重建索引頁面:
indexmaker /etc/mrtg.cfg > /var/www/mrtg/index.html

三安裝WWW串連數監視[預設5分鐘採集一次]

切換到超級使用者:
sudo -sH

建立WWW指令碼:
mkdir /opt/mrtg
vim /opt/mrtg/mrtg.www
#!/bin/bash
all=`netstat -a | grep www|awk {print $5}|sort | wc -l|awk {print$1 - 1}`
user=`netstat -a | grep www|awk {print $5}|cut -d":" -f1|sort| uniq |wc -l | awk {print $1 - 1}`
if [ "$all" = "-1" ]; then
echo 0
else
echo $all
fi
if [ "$user" = "-1" ]; then
echo 0
else
echo $user
fi
UPtime=`/usr/bin/uptime | awk {print $3 " " $4 " " $5}`
echo $UPtime
hostname


使指令碼可以執行:
chmod +755 /opt/mrtg/mrtg.www

修改 /etc/mrtg.cfg 在檔案最後加入www項目
Target[www]: `/opt/mrtg/mrtg.www`
MaxBytes[www]: 500
Options[www]: nopercent, growright
YLegend[www]: Online Users
ShortLegend[www]: %
LegendI[www]:   Connect :
LegendO[www]:   Online :
Title[www]: WWW Connect
PageTop[www]: <H1> WWW Connect </H1>

重建索引頁面:
indexmaker /etc/mrtg.cfg > /var/www/mrtg/index.html 四安裝記憶體使用量監視[預設5分鐘採集一次]

切換到超級使用者:
sudo -sH

建立RAM指令碼:
mkdir /opt/mrtg
vim /opt/mrtg/mrtg.ram
#!/bin/bash
# run this script to check the mem usage.
totalmem=`/usr/bin/free |grep Mem |awk {print $2}`


usedmem=`/usr/bin/free |grep Mem |awk {print $3}`
UPtime=`/usr/bin/uptime | awk {print $3""$4""$5}`
echo $totalmem
echo $usedmem
echo $UPtime
hostname


使指令碼可以執行:
chmod +755 /opt/mrtg/mrtg.ram

修改 /etc/mrtg.cfg 在檔案最後加入ram項目
Target[ram]: `/opt/mrtg/mrtg.ram`
#Unscaled[ram]: dwym
MaxBytes[ram]: 2048000
Title[ram]:Memory
ShortLegend[ram]: &
kmg[ram]:kB,MB
kilo[ram]:1024
YLegend[ram]:   Memory Usage :
Legend1[ram]:   Total Memory :
Legend2[ram]:   Used Memory :
LegendI[ram]:   Total Memory :
LegendO[ram]:   Used Memory :
Options[ram]: growright,gauge,nopercent
PageTop[ram]:<H1>Memory</H1>

重建索引頁面:
indexmaker /etc/mrtg.cfg > /var/www/mrtg/index.html


五安裝FTP串連數監視[預設5分鐘採集一次]

切換到超級使用者:
sudo -sH

建立FTP指令碼:
mkdir /opt/mrtg
vim /opt/mrtg/mrtg.ftp
#!/bin/bash
all=`netstat -a | grep ftp|awk {print $5}|sort | wc -l|awk {print$1 - 1}`
user=`netstat -a | grep ftp|awk {print $5}|cut -d":" -f1|sort| uniq |wc -l | awk {print $1 - 1}`
if [ "$all" = "-1" ]; then
echo 0
else
echo $all
fi
if [ "$user" = "-1" ]; then
echo 0
else
echo $user
fi
UPtime=`/usr/bin/uptime | awk {print $3 " " $4 " " $5}`

[1] [2] [3]  下一頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.