Home > Data Center Tips > > How to install and configure MRTG, an essential sys admin tool
Data Center Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 


How to install and configure MRTG, an essential sys admin tool


By Bill Bradford, Contributor
06.10.2009
Rating: --- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


I've been a systems administrator for fifteen years, and during that time one of the most useful pieces of software I've put into production is Tobi Oetiker's MRTG, which stands for Multi Router Traffic Grapher. MRTG is not limited to visualizing network traffic -- it can graph just about any data that can be retrieved with Simple Network Management Protocol (SNMP) or custom scripts.

In this column, I'll provide a walkthrough on how to perform a basic install of MRTG on a Solaris 10 Update 7 x86 VMware virtual machine running in 32-bit mode, monitoring its own network usage. The host name for my example machine is "sol10vm," but yours will be different. MRTG also runs well on other versions of Solaris, other Unix distributions, Mac OS X, most types of Linux and even Windows.

Installing MRTG on Solaris 10: Prerequisites
This MRTG tutorial has a few prerequisites. Most of them are similar to those required for my article on installing Nagios on Solaris, but some pieces of software have been updated. It assumes that you've installed the GNU GCC compiler and GNU Make that come on the Solaris 10 installation disc (or a newer version from Sunfreeware), and that the compiler works properly. In most cases, this just involves adding to your PATH environment variable. If you can run 'gcc' and 'gmake' and get the following output, you're probably good to go.

Another requirement is that the SNMP daemon is configured on your system or the system/router you want to monitor. Solaris 10 uses the Net-SNMP package, and Sun's documentation for it can be found here. For our purposes, you want a public communit...


BROWSE BY TAG
Data center networking,   Network management,   Sun Solaris Unix and Sparc server platforms,   Server hardware,   Unix operating systems and servers,   VIEW ALL TAGS

Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
Network management
HP's buyout of 3Com continues IT convergence push
Defining 'unified computing systems'
Remote server administration tools: Manage your data center from a distance
Solaris Project Crossbow offers virtualized network management
How to install and use RRDTool to speed up MRTG monitoring
Tackling data center airflow, network switch conflicts
With Cisco's Nexus 7000 switch, IP and Fibre Channel converge
Unix server vendors slow to adopt PCI Express
Microsoft allows Voltaire InfiniBand for Windows servers
Cisco sprouts green data center initiative

Sun Solaris Unix and Sparc server platforms
Are containerized data centers catching on outside Microsoft, Google?
Will Oracle hold a Sun yard sale as the acquisition's value declines?
Sun Microsystems customers stew in limbo
Will Solaris on x86 survive the Oracle-Sun acquisition and Linux?
Unix updates are slower, and users like it that way
New eBay data center director dishes
How should Sun customers read Oracle's latest rumblings?
With Exadata, Oracle embraces Sun hardware
Solaris Project Crossbow offers virtualized network management
IBM announces Power7 upgrade path in uncertain Unix market

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
configuration management database  (SearchDataCenter.com)
event forwarding  (SearchDataCenter.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary


y string with read-only access to network interface performance data. In short, you can usually edit as needed, then run as root to start things up. To test your SNMP daemon, run . If you get a lot of scrolling output, things are working.

For this demonstration, I'm using the Apache Web Server packages provided by Steve Christensen's Sunfreeware project, specifically Apache 2.2.11 and its dependencies (the expat, libiconv, openldap, sasl, zlib, openssl and libgcc packages). Building MRTG from source also requires that the gd (and its dependencies, xpm, fontconfig and libintl), libpng and jpeg-6b libraries are installed. These packages will install under , so make sure that is in your PATH and that and are in your system library search path (use crle; see "man crle" for details).

Once you've edited the file and started the Web server with , going to "http://yourhostname" with a Web browser should look something like this:

[IMAGE]
Click to enlarge.

Downloading and building MRTG
As of May 2009, the current version of MRTG is 2.16.2, and it can be downloaded from http://oss.oetiker.ch/mrtg/pub/. Once the source code is downloaded, uncompress it into a location of your choice (I like to use out of habit), change into the mrtg-2.16.2 directory, and run . The configure script will check your system for MRTG's prerequisites, then configure the software's build environment. As it finishes running, a message that says, "Config is DONE!" will appear and return you to a command prompt. At this prompt, you can then type "gmake" to build MRTG (it will only take a few seconds), and then "gmake install" to install MRTG under .

Configuring Apache for MRTG
There's not a lot of configuration required for Apache in order to work with MRTG. In most cases, creating a directory for your MRTG graphs and data files (in this case, ) will suffice.

How to configure MRTG
Change to the directory that you've created for your MRTG data files and use MRTG's cfgmaker script to automatically "walk" the SNMP tree of your device (in this case, the Solaris system that everything runs on).

This will create a basic configuration file called mrtg.cfg that is set up to monitor the single Ethernet interface on the machine ("e1000g0"). However, the file still needs minor edits. Open it in your favorite text editor and make the following changes:

  1. Uncomment the first WorkDir line and change the path to . This tells MRTG where to store its data files.
  2. Uncomment the Options line and remove ",bits". This makes the graphs update so that the most recent data is on the right-hand side and shows traffic in bytes.

Running MRTG
To test your MRTG installation, run the MRTG script that was installed in , giving it your newly created mrtg.cfg file as a parameter:

These warnings are expected and can be safely ignored the first time you run MRTG with a new configuration file -- it's complaining about not finding older log files to rotate or update.

If you look at the list of files that MRTG just created, one of them is HTML. If you open that file with a Web browser -- assuming everything was installed correctly -- the page will look something like this:

[IMAGE]
Click to enlarge.

This is nice, but we want to create a good index page for your MRTG installation, using the indexmaker script provided with the software:

This will result in a nicely formatted MRTG index page that comes in handy once you add multiple systems and interfaces to your MRTG configuration. It gives you a mission control-style overview of everything and lets users drill down to see specific interfaces and historical graphs.

[IMAGE]
Click to enlarge.

You'll notice that there are no data lines in the graph. This is because it was just created and has not been collecting data. In order to do that, you'll need to automate the MRTG command you just ran. I like to do this by creating a small shell script that is run by crontab.

In the directory that houses your MRTG configuration and data files, use your favorite text editor to create a Unix shell script that will run MRTG on demand. I like to call it do-mrtg, and mine looks something like this:

Make the script executable (), and run it once to test:

No output is good -- this means that the script ran MRTG and updated the data and log files with no problems.

To finish automating the MRTG data collection, add this script to the system crontab, set to run every five minutes. To edit the crontab, make sure your EDITOR environment variable is set (mine is set to "vi"), and run . The line to add to crontab should look like this:

script and redirect any output (errors, warnings, etc.) to .

After a while (depending on activity), you should have visible lines for incoming and outgoing traffic as well as numerical stats on the pages for specific network interfaces. If not, or if the numerical stats continually return "NaN" (not a number), check the MRTG log file and run MRTG again by hand to see what the problem is.

Further reading on MRTG
I suggest reading through the MRTG documentation and numerous third-party examples available on its website to get a deeper understanding of how MRTG works and how to interface it with more than just SNMP data.

Check in soon for my article on speeding up MRTG using RRDTool, another software offering from Tobi Oetiker.

ABOUT THE AUTHOR: Bill Bradford is the creator and maintainer of SunHELP and lives in Houston, Texas, with his wife Amy.

What did you think of this feature? Write to SearchDataCenter.com's Matt Stansberry about your data center concerns at mstansberry@techtarget.com.

Rate this Tip
To rate tips, you must be a member of SearchDataCenter.com.
Register now to start rating these tips. Log in if you are already a member.




DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



White Papers - Data Center Networking

The Intel IT Technology Center - Power, Performance and Mobility Solutions

HomeNewsTopicsITKnowledge ExchangeTipsBlogsMultimediaWhite PapersEvents
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2005 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts