Saturday, September 4, 2010

Add mrtg to nagios

Mrtg software may install during initial installation; you can verify if MRTG installed or not with following RPM command:
rpm -qa | grep mrtg
If mrtg already installed please see

step # 5; else use rpmfind.net to find MRTG rpm or up2date command to install MRTG software:
# up2date -v -i mrtg
Fedora Linux user can use yum command as follows to install MRTG:
# yum install mrtg

Step # 5 : Commands to Configure mrtg

(a) Create document root to store mrtg graphs/html pages:
# mkdir -p /var/www/html/mymrtg/
(b) Run any one of the following cfgmaker command to create mrtg configuration file:
#cfgmaker --global 'WorkDir: /var/www/html/mymrtg' --output /etc/mrtg/mymrtg.cfg public@localhost
OR (make sure your FQDN resolves, in following example i'm using rh9.test.com which is my router FQDN address)
# cfgmaker --global 'WorkDir: /var/www/html/mymrtg' --output /etc/mrtg/mymrtg1.cfg public@rh9.test.com
(c) Create default index page for your MRTG configuration:
# indexmaker --output=/var/www/html/mymrtg/index.html /etc/mrtg/mymrtg.cfg
(d) Copy all tiny png files to your mrtg path:
# cp -av /var/www/html/mrtg/*.png /var/www/html/mymrtg/
Run mrtg command from command line with your configuration file:
# mrtg /etc/mrtg/mymrtg.cfg
Note: You may get few warning message for first time; ignore them.
(b) Fire your favorite web browser (like FireFox :D ) and type url http://www.your.com/mymrtg/ or http://your-ip/mymrtg/


******************************
Now Your MRTG is running fine. Integrate it to nagios
************************************
Procedure to monitor Bandwidth Usages in Nagios:



1. Default installation directory of nagios is /usr/local/nagios/.

2. Open switch.cfg file
vi /usr/local/nagios/etc/objects/switch.cfg

3. Make changes according to your router specifications. Like,
define host{
use generic-switch
host_name Router_1
alias Router 1
address 172.17.42.22
hostgroups switches
}
4. You can also set PING, Uptime, Ports Link Status etc.
define service{
use generic-service ; Inherit values from a template
host_name Router_1 ; The name of the host the service is associated with
service_description PING ; The service description
check_command check_ping!200.0,20%!600.0,60% ; The command used to monitor the service
normal_check_interval 5 ; Check the service every 5 minutes under normal conditions
retry_check_interval 1 ; Re-check the service every minute until its final/hard state is determined
}

define service{
use generic-service ; Inherit values from a template
host_name Router_1
service_description Uptime
check_command check_snmp!-C public -o sysUpTime.0 -H 172.17.42.22
}

define service{
use generic-service ; Inherit values from a template
host_name Router_1
service_description Port 2 Link Status
check_command check_snmp!-C public -o ifOperStatus.2 -r 1 -H 172.17.42.22
}

define service{
use generic-service ; Inherit values from a template
host_name Router_1
service_description Port 2 Bandwidth Usage
check_command check_local_mrtgtraf!/var/www/html/mrtg/172.17.42.22_2.log!AVG!1000000,1000000!5000000,5000000
!10
}

5. Verify the configuration of nagios
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

6. Restart nagios service.
/etc/init.d/nagios restart

8 comments:

  1. Neat. It's almost as if you copied the instructions from http://bigunix.blogspot.com/2009/07/how-to-monitor-bandwidht-using-mrtg-and.html and didn't give that blog any credit.

    Well done?

    ReplyDelete
    Replies
    1. Indians usually dont care about credits and stuff..

      Delete
  2. You liar and cheat! I declare spoons on you! This behaviour is wholly unacceptable within the software/networking community. I hope you get crabs and poo on your head!

    ReplyDelete
  3. Knowledge is for sharing.Doesn't matter weather copied or not.So no need to blame anyone.

    ReplyDelete
  4. I agree with Shibu. If you have information, share it. Too many people get on their soapbox and preach about RTM or give vague help. If you've seen it, done it, are willing to share useable information, great, step up. If not, shut the hell up!

    ReplyDelete
  5. You anonymous, its not necessary to put only their wordarounds in blog. There is no copyrights for that. Dont bark here. You shut up and move on with your life. Dont talk like mentally retarded

    ReplyDelete
  6. hi,
    Cool, great stuff.
    Just a question how should i add another router eg.192.168.50.1 for monitoring. I have used snmpwalk command and i am getting the output but no statics on the graph.

    ReplyDelete
  7. What do you do if there are no png files in step d?

    ReplyDelete