论坛: UNIX系统 标题: FREEBSD下snmp+mrtg实现对网络流量、CPU、内存等的监视 复制本贴地址    
作者: SysHu0teR [syshunter]    版主   登录
      FREEBSD下snmp+mrtg实现对网络流量、CPU、内存等的监视

文章来源:www.20cn.net
作者:SysHu0teR(SysHunter)


FREEBSD上安装snmp+mrtg还是比较简单的,如果你已经安装好了apache的话,看下面:


一:安装snmp:

以下%为SHELL提示符,且----线内为要添加或修改的部分,不要把----也写进去了。-_-!

安装snmp:
%cd /usr/ports/net-mgmt/net-snmp
%make install

修改/etc/rc.conf:
%ee /etc/rc.conf
加入:
------------------------------------------------------------------
snmpd_enable="YES"
snmpd_flags="-a -p /var/run/snmpd.pid"
snmptrapd_enable="YES"
snmptrapd_flags="-a -p /var/run/snmptrapd.pid"
------------------------------------------------------------------


运行下:
%/etc/netstart

编辑snmpd.conf:
%ee /usr/local/share/snmp/snmpd.conf
加入一行:
-------------------------------------------------------------
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的配置文件:
%/usr/local/bin/cfgmaker public@mail.ahcbd.net > mrtg.cfg
记得将上面的mail.ahcbd.net换成你的主机名,

编辑mrtg.conf:
%ee mrtg.cfg
修改如下:
-----------------------------------------------------------------------------
LoadMIBs: /usr/local/share/snmp/mibs/UCD-SNMP-MIB.txt
WorkDir: /usr/local/www/apache22/data/wh-hisense/mrtg
Language: chinese
--------------------------------------------------------------------------------


并在文件尾加入:
-----------------------------------------------------------------------------------------------------
#Monitoring TCP connections
Target[tcpopen]: .1.3.6.1.2.1.6.9.0&.1.3.6.1.2.1.6.9.0:public@mail.ahcbd.net
Options[tcpopen]: nopercent,growright,gauge,noinfo
Title[tcpopen]: Open TCP connections
PageTop[tcpopen]: <h1>Open TCP connections</H1>
MaxBytes[tcpopen]: 1000000
YLegend[tcpopen]: # conns
ShortLegend[tcpopen]: connections
LegendI[tcpopen]:  Connections:
Legend1[tcpopen]: Open TCP connections

#monitoring User vs Idle CPU usage
Target[kontor.cpu]:ssCpuRawUser.0&ssCpuRawIdle.0:public@mail.ahcbd.net
RouterUptime[kontor.cpu]: public@mail.ahcbd.net
MaxBytes[kontor.cpu]: 100
Title[kontor.cpu]: CPU LOAD
PageTop[kontor.cpu]: <H1>User CPU Load %</H1>
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
Target[kontor.usrsys]:ssCpuRawUser.0&ssCpuRawSystem.0:public@mail.ahcbd.net
RouterUptime[kontor.usrsys]: public@mail.ahcbd.net
MaxBytes[kontor.usrsys]: 100
Title[kontor.usrsys]: CPU LOAD
PageTop[kontor.usrsys]: <H1>CPU (user and system) Load %</H1>
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
Target[kontor.cpusum]:ssCpuRawUser.0&ssCpuRawUser.0:public@mail.ahcbd.net +

ssCpuRawSystem.0&ssCpuRawSystem.0:public@mail.ahcbd.net
+ ssCpuRawNice.0&ssCpuRawNice.0:public@mail.ahcbd.net
RouterUptime[kontor.cpusum]: public@mail.ahcbd.net
MaxBytes[kontor.cpusum]: 100
Title[kontor.cpusum]: CPU LOAD
PageTop[kontor.cpusum]: <H1>Active CPU Load %</H1>
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


Target[freemem]: .1.3.6.1.4.1.2021.4.11.0&.1.3.6.1.4.1.2021.4.11.0:public@mail.ahcbd.net
Options[freemem]: nopercent,growright,gauge,noinfo
Title[freemem]: Free Memory
PageTop[freemem]: <h1>Free Memory</h1>
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
--------------------------------------------------------------------------------------
记得将上面每处的mail.ahcbd.net换成你的主机名。且更改上面CPU,MEM等各部分的排列顺序等同于其在网页中的排列顺序


生成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
--------------------------------------------------------------------

现在你可以用http://yourdomain.domain/mrtg/看到了。

End!
                                                                       
                                                            ---------By SysHu0teR(syshunter)
                                                                                    01.18.2006



[此贴被 SysHu0teR(syshunter) 在 01月18日17时29分 编辑过]

地主 发表时间: 06-01-18 17:28

回复: SysHu0teR [syshunter]   版主   登录
演示地址: http://mail.wh-hisense.com/mrtg/


有时间去学学排版

B1层 发表时间: 06-01-18 17:30

回复: 尤里西斯 [amr]   论坛用户   登录
代码:
安装snmp:
%cd /usr/ports/net-mgmt/net-snmp
%make install

修改/etc/rc.conf:
%ee /etc/rc.conf
加入:
------------------------------------------------------------------
snmpd_enable="YES"
snmpd_flags="-a -p /var/run/snmpd.pid"
snmptrapd_enable="YES"
snmptrapd_flags="-a -p /var/run/snmptrapd.pid"
------------------------------------------------------------------


运行下:
%/etc/netstart

编辑snmpd.conf:
%ee /usr/local/share/snmp/snmpd.conf
加入一行:
-------------------------------------------------------------
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的配置文件:
%/usr/local/bin/cfgmaker public@mail.ahcbd.net > mrtg.cfg
记得将上面的mail.ahcbd.net换成你的主机名,

编辑mrtg.conf:
%ee mrtg.cfg
修改如下:
-----------------------------------------------------------------------------
LoadMIBs: /usr/local/share/snmp/mibs/UCD-SNMP-MIB.txt
WorkDir: /usr/local/www/apache22/data/wh-hisense/mrtg
Language: chinese
--------------------------------------------------------------------------------


并在文件尾加入:
-----------------------------------------------------------------------------------------------------
#Monitoring TCP connections
Target[tcpopen]: .1.3.6.1.2.1.6.9.0&.1.3.6.1.2.1.6.9.0:public@mail.ahcbd.net
Options[tcpopen]: nopercent,growright,gauge,noinfo
Title[tcpopen]: Open TCP connections
PageTop[tcpopen]: <h1>Open TCP connections</H1>
MaxBytes[tcpopen]: 1000000
YLegend[tcpopen]: # conns
ShortLegend[tcpopen]: connections
LegendI[tcpopen]:  Connections:
Legend1[tcpopen]: Open TCP connections

#monitoring User vs Idle CPU usage
Target[kontor.cpu]:ssCpuRawUser.0&ssCpuRawIdle.0:public@mail.ahcbd.net
RouterUptime[kontor.cpu]: public@mail.ahcbd.net
MaxBytes[kontor.cpu]: 100
Title[kontor.cpu]: CPU LOAD
PageTop[kontor.cpu]: <H1>User CPU Load %</H1>
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
Target[kontor.usrsys]:ssCpuRawUser.0&ssCpuRawSystem.0:public@mail.ahcbd.net
RouterUptime[kontor.usrsys]: public@mail.ahcbd.net
MaxBytes[kontor.usrsys]: 100
Title[kontor.usrsys]: CPU LOAD
PageTop[kontor.usrsys]: <H1>CPU (user and system) Load %</H1>
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
Target[kontor.cpusum]:ssCpuRawUser.0&ssCpuRawUser.0:public@mail.ahcbd.net +

ssCpuRawSystem.0&ssCpuRawSystem.0:public@mail.ahcbd.net
+ ssCpuRawNice.0&ssCpuRawNice.0:public@mail.ahcbd.net
RouterUptime[kontor.cpusum]: public@mail.ahcbd.net
MaxBytes[kontor.cpusum]: 100
Title[kontor.cpusum]: CPU LOAD
PageTop[kontor.cpusum]: <H1>Active CPU Load %</H1>
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


Target[freemem]: .1.3.6.1.4.1.2021.4.11.0&.1.3.6.1.4.1.2021.4.11.0:public@mail.ahcbd.net
Options[freemem]: nopercent,growright,gauge,noinfo
Title[freemem]: Free Memory
PageTop[freemem]: <h1>Free Memory</h1>
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




[此贴被 尤里西斯(amr) 在 07月20日18时54分 编辑过]

B2层 发表时间: 06-07-20 18:53

回复: yange1111 [yange1111]   论坛用户   登录
[MP=0,0,true]http://www.5573wow.com/1860.wma[/MP]

dfgdgdf [FLASH=0,0]http://www.5573wow.com/1860.wma[/FLASH] 


[此贴被 NetDemon(netdemon) 在 09月07日18时31分 编辑过]

B3层 发表时间: 06-08-22 22:26

回复: sumrin [sumrin]   论坛用户   登录
我擦 freebsd 的ports的功能还是很强大的 安装软件还是 很方面的 不过时间就是慢点

如果时间短 就用pkg_add

B4层 发表时间: 12-04-29 15:46

论坛: UNIX系统

20CN网络安全小组版权所有
Copyright © 2000-2010 20CN Security Group. All Rights Reserved.
论坛程序编写:NetDemon

粤ICP备05087286号