1. Switch to enable SNMP protocol
2. Installing MRTG
Yum-y Install MRTG
3. Configure MRTG
(1) Create the configuration file, if there are multiple switches, you can create a corresponding configuration file for each switch
Mkdir-p/USR/LOCAL/MRTG
cfgmaker-output=/usr/local/mrtg/switch.cfg [email protected] Switch IP
The switchw.cfg configuration file generated at this time records information such as the model of the monitored switch, all ports being used, VLAN, current rate, and so on.
This needs to be liked, we do not have to configure each.
(2) Create a web directory of traffic graphs at access time
Mkdir-p/usr/local/mrtg/share
(3) Modify the configuration file generated by the first step to point the working directory to the web directory you set
Vim/usr/local/mrtg/switch.cfg
# for UNIX
Workdir:/usr/local/mrtg/share
(4) Generate traffic map in working directory
Env LANG=C/USR/BIN/MRTG/USR/LOCAL/MRTG/SWITCH.CFG
After the execution, there will be alarm prompts, we need to execute several times, until no alarm information for the general execution 3 times can
[[email protected] 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.h tml 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.l OG 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-m Onth.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.o LD 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-w Eek.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-y Ear.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-d Ay.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.h tml 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.l OG 10.10.15.1_515.old 10.10.15.1-year.png
(5) Since we need real-time monitoring, we need to set up a scheduled task to meet our needs, which is set to update every 5 minutes
Vim/etc/crontab
*/5 * * * */usr/bin/env lang=c/usr/bin/mrtg/usr/local/mrtg/switch.cfg >>/dev/null >2&1
(6) Generate summary home index.html
indexmaker-output=/usr/local/mrtg/share/index.html-title= "Mainswitch Traffic Monitoring"/usr/local/mrtg/ Switch.cfg
4. Configure Apache to enable Web Access
After the Yum installation is complete, the configuration file/etc/httpd/conf.d/mrtg.conf is generated on Apache and is configured as follows:
[Email protected] 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 is 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>
We can access it through HTTP://IP/MRTG, the effect is as follows:
Through the above we can view the traffic information of the switch in real-time, but we want to realize the traffic monitoring alarm, we need nagios to read the MRTG monitor traffic information to achieve
In the new version of Nagios, there are two plugins, CHECK_MRTG and Check_mrtgtraf, and the relevant parameters have been configured so that we can call them directly.
1. First we need to define the switch and monitoring services
We can modify the/usr/local/nagios/etc/switch.cfg file directly.
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 are 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
}
Where 10.10.15.1_1794.log 1794 represents the 1794 port of the switch, we can configure it according to the effective information of MRTG monitoring.
The "AVG" parameter means to take the statistical average of the bandwidth, "1000000,1000000" parameter refers to the incoming alarm threshold (in bytes), "5000000,5000000" is the output traffic emergency threshold (in bytes), "10" Refers to a state of emergency (which should be updated every 5 minutes) if the MRTG log does not return data for more than 10 minutes.
2. Check the Nagios configuration file and restart
/usr/local/nagios/bin/nagios-v/usr/local/nagios/etc/nagios.cfg
Service Nagios Restart
MRTG Monitor switch router traffic and Nagios alarms