Monitor Linux routers and firewalls with MRTG
Published: 01 Aug 2002 08:40 BST
MRTG, or Multi Router Traffic Grapher, is a popular monitoring and statistics tool for use on Linux platforms. It was designed to monitor the traffic load on network links, but it's highly extensible and configurable. Not only can you watch interfaces on routers and switches, but you can also analyze Linux system variables. Although this is usually done with the Simple Network Management Protocol (SNMP), MRTG also supports the use of local scripts to feed it data. The data is then converted into HTML with graphs in PNG format for a visual representation of your network.
Overview of SNMP
Before we delve too deeply into the installation and configuration of MRTG, it is important to understand how MRTG and SNMP work together. By default, MRTG will take an SNMP community string and a device hostname or IP address and discover what it needs to know. This is done by polling Management Information Base (MIB) objects predefined for all SNMP-ready devices. A MIB is basically a database of variables that corresponds to a system value. Basic examples include information such as system name, interface type, and uptime.
Most vendors will have MIBs for their line of products, and these will conform to SNMP standards. On the device, SNMP then needs to be enabled and a community string set. Such configurations will vary from vendor to vendor and sometimes from device to device. On Cisco products, for instance, the configuration command snmp-server is used as follows:
snmp-server community c1sc0 RO
This informs the Cisco IOS to provide read-only access to a querying SNMP tool that provides the community string c1sc0. It is best that you treat SNMP strings like passwords and configure them appropriately. SNMP is probably already configured and running if you currently use other network and system monitoring tools, such as HP OpenView, Cisco Works, or OpenNMS.
Linux will also need to be configured to provide real-time data to MRTG. This can be done with SNMP or through the use of local scripts. To listen for incoming SNMP requests, you will need to install and configure snmpd. Configuration is done through the snmpd.conf file and requires you to set your community string. For a standard UCD SNMP implementation, the line in snmpd.conf will look something like this:
com2sec readonly default liNuX42
Notice that once again, we are giving only read-only access to SNMP agents. Read-write access is also configurable, but if you don't need it, don't configure it. With read-only, you will be able to view only statistics and configuration options. Although this is something that should be monitored closely for security reasons, it is not nearly as dangerous as allowing remote commands to be executed via SNMP.
Installing and configuring MRTG
MRTG, like more and more packages these days, should be available through your favorite automated installer. So whether it is APT or up2date, that is usually the quickest way to get it onto your system. Alternatively, source and RPM distributions are available from the maintainer's site at MRTG.org. MRTG has a number of dependencies as well, the most important being Perl, gd, libpng, and zlib. Keep this in mind during installation if you encounter problems. Source code installation follows the standard scheme with:
tar xpfz mrtg-2.9.18.tar.gz
./configure
make
make install
Installing with RPM is also easy. The package name may vary, but you simply use the command:
rpm --ivh mrtg-2.9.18.rpm
Once MRTG is installed on your system, you may need to configure a Web directory where it will place its HTML and PNGs for viewing. Use mkdir to create a directory called mrtg under your main HTTP path and modify your permissions. For example:
mkdir /var/www/mrtg
chmod 755 /var/www/mrtg
The next step is to create a configuration for MRTG to use. The quickest way to do this is by running cfgmaker and passing it the SNMP community string and device and outputting it to a text file, like this:
cfgmaker c1sc0@192.168.66.72 > /etc/mrtg.cfg
Then, edit the new mrtg.cfg file and add a line listing the path to your working directory (where your MRTG-related files will be stored), like this:
WorkDir: /var/www/mrtg
Note that the device can be represented as either an IP address or a hostname. Also, cfgmaker can support a variety of options and settings at the command line, depending on the version. The best way to get started, though, is to use the default options. You can always make changes directly to the configuration file later.
Full Talkback thread
1 comment






