Using the Experimental Feature if-filter in MRTG 2.16 cfgmaker

Apr 22, 2010

I have been using the MRTG package for many years and it remains a quick and easy way to collect longitudinal data from network devices that support SNMP (and it can be extended to do more, but that’s a topic for a future posting). In this post, I am writing about some of the experimental features of MRTG in the current release 2.16. Keep in mind that these features are still under development and so information in this posting may be out of date at some future time. I will endeavor to update this posting as things change to keep it current.

At its heart, MRTG is a polling engine and is usually used to grab two scaler data items (usually via SNMP) which by default are added to PNG-based graphs which are made available though a web page. There have been several tutorials on how to setup MRTG. A good one is available in a book called Open Source Network Administration (Prentice Hall Series in Computer Networking and Distributed Systems) and is available on the web as of this posting at On FreeBSD, MRTG is available via The FreeBSD Ports collection in /usr/ports/net-mgmt/mrtg directory and can be installed from there very easily.

In this posting, I am using cfgmaker and indexmaker. Both come with the MRTG package and are useful ways to quicky generate the configuration files used by MRTG and then build a web page that can display the PNG-graphs generated when MRTG does its polling.

Recently, I was updating the pages I maintain for the Southeast Texas GigaPOP (SETG), a consortium of higher-education institutions that make use of a Houston-area MAN to facilitate high-speed network connections among themselves and to the Lonestar Research and Education Network (LEARN). I had been using MRTG for years to plot the usage on the links that make up the MAN and wanted to update that installation to the latest software. Because the MAN make use of Cisco Catalyst 6500 switches and a Juniper MX-Series switch, I thought it would be great to make use of the new experimental features to make the usage information easier to navigate and eliminate information that would not be interesting to the consortium members.

The new experimental features in cfgmaker seem to be optimized for Cisco Systems gear and that made it very easy to customize the configuration file for the Cisco Catalyst 6500s in the SETG MAN. For these devices, I was primarily interested in reporting on the input and output usage on the physical interfaces. To create a configuration file just for those interfaces, I invoked cfgmaker using this command line:

cfgmaker --ifdesc=alias --global 'options[_]:bits' --global 'WriteExpires:Yes' --global 'IconDir:/icons/' --global 'WorkDir:/local/mrtg/data/devicename' --output='/local/mrtg/cfg/devicename.cfg' --if-filter='((!$if_is_ciscovlan && !$if_is_loopback && $if_type!=53 && $if_type!=1) && $if_admin && $if_oper)' --snmp-options=:::::2

The experimental feature exploited here is the if-filter directive. In this particular case, I didn’t want anything related to Cisco VLANs, Loopbacks or devices of type 1 (a catch-all for types not specified in the SNMP standards) or 53 (a virtual interface). I wanted the interfaces reported on to be both administratively and operationally up. This generated a configuration file that contained only physical interfaces and that satisfied my requirements for these devices.

For the Juniper MX, it was harder because the SNMP device type reported for the management port and some other ports that were not of interest would not be covered by the same filter. So, I modified the filter for the Juniper to explicitly exclude the devices with descriptions that matched the names of the devices that were not of interest. The command line I used for it was this:

cfgmaker --ifdesc=alias --global 'options[_]:bits' --global 'WriteExpires:Yes' --global 'IconDir:/icons/' --global 'WorkDir:/local/mrtg/data/devicename' --output='/local/mrtg/cfg/devicename.cfg' --if-filter='((!$if_is_loopback && $if_type!=53 && $if_type!=1 && $if_type!=135 && ($if_description !~ /em|fxp|pd|pe|gr|ip|vt|mt|pd/)) && $if_admin && $if_oper)' --snmp-options=:::::2

Here I added device type 135 (Layer 2 VLAN using 802.1Q) and used the $if_description along with a Perl pattern binding operator to eliminiate those devices with descriptions that were not of interest.

After I updated mrtg to use the new configuration files in its polling, I was ready to use indexmaker to build the index pages. The only thing I was doing different from the default here is setting the title of the page. The command line looks like this:

indexmaker --title="Devicename Node" /local/mrtg/cfg/devicename.cfg

The results of all this work is available at [Due to some idiosyncrasies with how IPv6 is currently configured for SETG, you may want to try the IPv4 URL which is]

Of course, there are more experimental features available in MRTG than if-filter, but it was the one I thought most interesting and about which I could not find much information in other blogs. I do hope that the MRTG team will keep it in the software as they continue to develop the next release of MRTG.

Share with others

4 Responses so far | Have Your Say!

  1. jeff chandler
    April 23rd, 2010 at 7:24 pm #

    I have used mrtg as well for several years. Currently I use it to pull data from our brocade switches to track read and write trends from our Hitachi SAN.
    I still use a fairly old version as was wondering if MRTG supports SNMP V3 authentication.

  2. Stan Barber
    April 23rd, 2010 at 7:37 pm #

    Yes, it appears that MRTG does uspport SNMPv3 authentication. I have a posting about using SNMPv3 that shows the basics of how to get started using MRTG and Cisco IOS.

  3. Steve Shipway
    May 13th, 2010 at 4:07 pm #

    You mention a couple of books which have a section on MRTG. I’ll use the opportunity to plug my own book, “Using MRTG with RRDTool and Routers2″ which can be bought online from This covers a huge range of features and tips and techniques, including SNMPv3, the counter rollover problem, if-filter and much more.

  4. Stan Barber
    May 13th, 2010 at 6:57 pm #

    Steve, glad for you to promote your book. I only list books in my post I have personally read and used and I have not had a chance to read yours (so far).