当前位置:操作系统 > Unix/Linux >>

FREEBSD下snmp+mrtg实现对网络流量、CPU、内存等的监视

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
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,