mrtg监控短信报警 linux,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

Order deny,allow

#    Deny from all

Allow from all

Allow from 127.0.0.1

Allow from ::1

# Allow from .example.com

我们可以通过http://ip/mrtg访问了,效果如下:

a9d74566e8535e8e71ca6a3e93769c06.png

通过以上我们就可以实时查看交换机的流量信息了,但是我们要想实现流量监控报警,我们就需要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

Nagios 的详细介绍:请点这里

Nagios 的下载地址:请点这里

0b1331709591d260c1c78e86d0c51c18.png

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值