Mrtg监控交换机路由器流量以及Nagios报警


1.交换机开启snmp协议
2.安装mrtg
yum -y install mrtg
3.配置mrtg
(1)创建配置文件,若有多个交换机,可对每个交换机创建相应的配置文件
mkdir -p /usr/local/mrtg
cfgmaker -output=/usr/local/mrtg/switch.cfg public@交换机IP

此时生成的switchw.cfg配置文件,记录着所监控交换机的型号,所有正在使用的端口,vlan,当前的速率等信息。
这点需要赞一下,不用我们挨个配置了。
(2)创建访问时流量图的web目录
mkdir -p /usr/local/mrtg/share
(3)修改第一步生成的配置文件,将工作目录指向所设置的web目录
vim /usr/local/mrtg/switch.cfg
#  for UNIX
WorkDir: /usr/local/mrtg/share
(4)在工作目录下生成流量图
env LANG=C /usr/bin/mrtg /usr/local/mrtg/switch.cfg
执行完后,会有告警提示,我们需多次执行,直至无报警信息为之,一般执行3次即可
[root@srv10100173 share]# ls
10.10.15.1_1794-day.png    10.10.15.1_1795.log        10.10.15.1_1796.old       10.10.15.1_257-year.png   10.10.15.1_513.html       10.10.15.1_514-month.png  10.10.15.1_515-week.png  index.html
10.10.15.1_1794.html       10.10.15.1_1795-month.png  10.10.15.1_1796-week.png  10.10.15.1_258-day.png    10.10.15.1_513.log        10.10.15.1_514.old        10.10.15.1_515-year.png  mrtg-l.png
10.10.15.1_1794.log        10.10.15.1_1795.old        10.10.15.1_1796-year.png  10.10.15.1_258.html       10.10.15.1_513-month.png  10.10.15.1_514-week.png   10.10.15.1-day.png       mrtg-m.png
10.10.15.1_1794-month.png  10.10.15.1_1795-week.png   10.10.15.1_257-day.png    10.10.15.1_258.log        10.10.15.1_513.old        10.10.15.1_514-year.png   10.10.15.1.html          mrtg-r.png
10.10.15.1_1794.old        10.10.15.1_1795-year.png   10.10.15.1_257.html       10.10.15.1_258-month.png  10.10.15.1_513-week.png   10.10.15.1_515-day.png    10.10.15.1.log
10.10.15.1_1794-week.png   10.10.15.1_1796-day.png    10.10.15.1_257.log        10.10.15.1_258.old        10.10.15.1_513-year.png   10.10.15.1_515.html       10.10.15.1-month.png
10.10.15.1_1794-year.png   10.10.15.1_1796.html       10.10.15.1_257-month.png  10.10.15.1_258-week.png   10.10.15.1_514-day.png    10.10.15.1_515.log        10.10.15.1.old
10.10.15.1_1795-day.png    10.10.15.1_1796.log        10.10.15.1_257.old        10.10.15.1_258-year.png   10.10.15.1_514.html       10.10.15.1_515-month.png  10.10.15.1-week.png
10.10.15.1_1795.html       10.10.15.1_1796-month.png  10.10.15.1_257-week.png   10.10.15.1_513-day.png    10.10.15.1_514.log        10.10.15.1_515.old        10.10.15.1-year.png
(5)由于我们需要实时监控,因此我们需要设置计划任务,以满足我们的需求,在此设置每5分钟更新一次
vim /etc/crontab
*/5 * * * * /usr/bin/env LANG=C  /usr/bin/mrtg /usr/local/mrtg/switch.cfg >> /dev/null 2>&1 
(6)生成汇总首页index.html
indexmaker -output=/usr/local/mrtg/share/index.html -title="MainSwitch Traffic Monitoring"  /usr/local/mrtg/switch.cfg


4.配置apache,使其能够web访问
yum安装完成后会在apache上生成配置文件/etc/httpd/conf.d/mrtg.conf,配置如下:
[root@srv10100173 mrtg]# cat /etc/httpd/conf.d/mrtg.conf 
#
# This configuration file maps the mrtg output (generated daily)
# into the URL space.  By default these results are only accessible
# from the local host.

Alias /mrtg /usr/local/mrtg/share


<Location /mrtg>
    Order deny,allow
#    Deny from all
    Allow from all
    Allow from 127.0.0.1
    Allow from ::1
    # Allow from .example.com
</Location>
我们可以通过http://ip/mrtg访问了,效果如下:


通过以上我们就可以实时查看交换机的流量信息了,但是我们要想实现流量监控报警,我们就需要nagios读取mrtg监控的流量信息来实现了
在新版的nagios中,有check_mrtg和check_mrtgtraf这两个插件,并且相关参数已经配置好了,我们可以直接调用。
1.首先我们要定义交换机和监控服务
我们可以直接修改/usr/local/nagios/etc/switch.cfg这个文件
vim /usr/local/nagios/etc/switch.cfg
define host{
   use     generic-switch      ; Inherit default values from a template
   host_name   huawei-ER-3100      ; The name we're giving to this switch
   alias       huawei-ER-3100  ; A longer name associated with the switch
   address     10.10.15.1      ; IP address of the switch
   hostgroups  switches        ; Host groups this switch is associated with
   }
define service{
   use         generic-service ; Inherit values from a template
   host_name   huawei-ER-3100
   service_description Interface 1794 Bandwidth Usage
   check_command       check_local_mrtgtraf!/usr/local/mrtg/share/10.10.15.1_1794.log!AVG!1000000,1000000!5000000,5000000!10
   }
其中10.10.15.1_1794.log的1794表示交换机的1794端口,我们可以根据mrtg监测的有效信息进行配置。
"AVG"参数的意思是取带宽的统计平均值,"1000000,1000000"参数是指流入的告警门限 (以字节为单位),"5000000,5000000"是输出流量紧急状态门限(以字节为单位),"10"是指如果MRTG日志如果超过10分钟没有数据 返回一个紧急状态(应该每5分钟更新一次)


2.检查nagios配置文件并重启
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
service nagios restart

Linux Mrtg系统监控 

在Ubuntu下配置Mrtg监控Nginx和服务器系统资源

使用 snmp+Mrtg 监控 Linux 系统

Mrtg服务器搭建(监控网络流量)

网络监控器Nagios全攻略

Nagios搭建与配置详解

Nginx环境下构建Nagios监控平台

在RHEL5.3上配置基本的Nagios系统(使用Nagios-3.1.2)

CentOS 5.5+Nginx+Nagios监控端和被控端安装配置指南

Ubuntu 13.10 Server 安装 Nagios Core 网络监控运用

Nagios 的详细介绍:请点这里
Nagios 的下载地址:请点这里

本文永久更新链接地址:

相关内容