Homepage

Wednesday, July 6, 2016

MRTG with NAGIOS

Hi, All Here is some document relate system that it will can help you all to build  system monitor network traffic. you can follow the instruction step by step below:

Install MRTG. 
Configure and setup MRTG. 
Add new definitions to Nagios. (Part 2) 
Setup and restart Nagios to view new bandwidth defined services. (Part 2)

Part 1 - Install MRTG on CentOS
We will cover in this initial article the MRTG installation for CentOS 6.4, it works too in CentOS 6.3 and other distro.
First install the snmp tools needed.
# yum install net-snmp net-snmp-utils rrdtool
Afterwards install the MRTG
#yum install mrtg
Now it's time to decide where do you want to see your graphs and infos. Maybe in a MRTG dir in  wwwroot where you will find all the datas in the future. 
mkdir /var/www/html/mrtg
Now let's go an create a good mrtg.conf file. It's important, so take a while doing the correct settings.
Used command cfgmaker to create log file relate with information of device
cfgmaker --ifref=descr --ifdesc=descr --snmp-options=:::::2 --global 'WorkDir: /var/www/html/mrtg/router_name/' --global 'Options[_]: bits' --output /etc/mrtg/mrtg_router_name.cfg "snmp commnunity"@x.x.x.x":::::2"
  • Snmp-options=:::::2 used for data graphing over 100Mb/s
And then we need to create index file for storing data information by using command below
# indexmaker --output=/var/www/mrtg/index.html /etc/mrtg/mrtg_router_name.cfg
You can you command to show graph manually after 5 minute
# /usr/bin/mrtg /etc/mrtg/mrtg.cfg --lock-file /var/lock/mrtg/mrtg_l --confcache-file /var/lib/mrtg/mrtg.ok
Then we need to create crontab in order to to run command to generate data every 5 minutes by
# vim /etc/cron.d/mrtg
*/5 * * * * root LANG=C LC_ALL=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg --lock-file /var/lock/mrtg/mrtg_l --confcache-file /var/lib/mrtg/mrtg.ok
Note: one command just can execute for only one device, if you have many device you need to create files more to execute to trap data from other devices.
#service httpd restart
Then you can access by http://x.x.x.x/mrtg
 
  1. Part 2 - Monitoring bandwidth with Nagios - Settings alerts.
Add a service to Nagios to monitor port bandwidth 
check_local_mrtgtraf uses the MRTG. So, first install MRTG for this to work properly. The *.log file mentioned below should point to the MRTG log file on your system, the MRTG work directory we have created. The check_local_mrtgtraf is included in Nagios plugins.
#vim /usr/local/nagios/object/router_name.cfg
And add this parameter below:
define service{
use           generic-service
host_name   core-switch
service_description Port 1 Bandwidth Usage
check_command  check_local_mrtgtraf!/var/www/mrtg/router_name_interface.log!AVG!1000000,2000000!5000000,5000000!10
}
The "AVG" option tells it that it should use average bandwidth statistics.
The "1000000,2000000" options are the warning thresholds (in bytes) for incoming traffic rates.
The "5000000,5000000" are critical thresholds (in bytes) for outgoing traffic rates.
The "10" option causes the plugin to return a CRITICAL state if the MRTG log file is older than 10 minutes (it should be updated every 5 minutes). 
For more check_local_mrtgtraf properties, run the plugin help.  
Remember to validate Nagios settings and restart if all settings are ok.
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
# /etc/init.d/nagios restart

No comments:

Post a Comment