一:安装snmp:
以下%为SHELL提示符,
安装snmp:
%cd /usr/ports/net-mgmt/net-snmp
%make install
加入:
------------------------------------------------------------------
snmpd_enable="YES"
snmpd_flags="-a -p /var/run/snmpd.pid"
snmptrapd_enable="YES"
snmptrapd_flags="-a -p /var/run/snmptrapd.pid"
------------------------------------------------------------------
运行下:
%/etc/netstart
加入一行:
-------------------------------------------------------------
rocommunity public #默认让snmp使用public用户
--------------------------------------------------------------
启动snmpd:
%/usr/local/etc/rc.d/snmpd.sh start
二:安装mrtg:
确定ports下的mrtg在什么位置:
%whereis mrtg
mrtg: /usr/ports/net-mgmt/mrtg
安装mrtg:
%cd /usr/ports/net-mgmt/mrtg
%make install
进入你apache的data目录(视个人情况而定,我的是/usr/local/www/apache22/data/wh-hisense/):
%cd /usr/local/www/apache22/data/wh-hisense
在当前的WEB目录创建mrtg的目录:
%mkdir mrtg
三:配置mrtg:
进入mrtg的配置文件所在目录:
%cd /usr/local/etc/mrtg
用cfgmaker创建mrtg的配置文件:
%ee mrtg.cfg
修改如下:
#####################################
WorkDir: /usr/local/www/apache22/data/wh-hisense/mrtg #注:去掉前面的#号哟,冒号后面不要有空格,否则会出错.
Language: gb2312 #注:这表示简体中文版,,这可是自己加上去的哦!!!
#####################################
并在文件尾加入,既cpu,内存等的监视:
-----------------------------------------------------------------------------------------------------
#Monitoring TCP connections
Options[tcpopen]: nopercent,growright,gauge,noinfo
Title[tcpopen]: Open TCP connections
PageTop[tcpopen]:
Open TCP connections
MaxBytes[tcpopen]: 1000000
YLegend[tcpopen]: # conns
ShortLegend[tcpopen]: connections
LegendI[tcpopen]: Connections:
Legend1[tcpopen]: Open TCP connections
#monitoring User vs Idle CPU usage
MaxBytes[kontor.cpu]: 100
Title[kontor.cpu]: CPU LOAD
PageTop[kontor.cpu]:
User CPU Load %
Unscaled[kontor.cpu]: ymwd
ShortLegend[kontor.cpu]: %
YLegend[kontor.cpu]: CPU Utilization
Legend1[kontor.cpu]: User CPU in % (Load)
Legend2[kontor.cpu]: Idle CPU in % (Load)
LegendI[kontor.cpu]: User
LegendO[kontor.cpu]: Idle
Options[kontor.cpu]: growright,nopercent
#monitoring User vs System CPU usage
MaxBytes[kontor.usrsys]: 100
Title[kontor.usrsys]: CPU LOAD
PageTop[kontor.usrsys]:
CPU (user and system) Load %
Unscaled[kontor.usrsys]: ymwd
ShortLegend[kontor.usrsys]: %
YLegend[kontor.usrsys]: CPU Utilization
Legend1[kontor.usrsys]: User CPU in % (Load)
Legend2[kontor.usrsys]: System CPU in % (Load)
LegendI[kontor.usrsys]: User
LegendO[kontor.usrsys]: System
Options[kontor.usrsys]: growright,nopercent
#monitoring Active CPU usage
MaxBytes[kontor.cpusum]: 100
Title[kontor.cpusum]: CPU LOAD
PageTop[kontor.cpusum]:
Active CPU Load %
Unscaled[kontor.cpusum]: ymwd
ShortLegend[kontor.cpusum]: %
YLegend[kontor.cpusum]: CPU Utilization
Legend1[kontor.cpusum]: Active CPU in % (Load)
LegendI[kontor.cpusum]: Active
Options[kontor.cpusum]: growright,nopercent
Options[freemem]: nopercent,growright,gauge,noinfo
Title[freemem]: Free Memory
PageTop[freemem]:
Free Memory
MaxBytes[freemem]: 1000000
kMG[freemem]: k,M,G,T,P,X
YLegend[freemem]: bytes
ShortLegend[freemem]: bytes
LegendI[freemem]: Free Memory:
Legend1[freemem]: Free memory, not including swap, in bytes
--------------------------------------------------------------------------------------
生成index.html文件:
/usr/local/bin/indexmaker --title="流量监控" --output=/home/http/mrtg/index.html mrtg.cfg
多运行几次:
/usr/local/bin/mrtg mrtg.cfg
直到没有出错提示为止
加入crontab每隔2分钟让数据刷新一次:
%ee /etc/crontab
------------------------------------------------------------------------
*/2 * * * * root /usr/local/bin/mrtg /usr/local/etc/mrtg/mrtg.cfg
--------------------------------------------------------------------