MRTG Traffic Graphs

Barry O'Donovan edited this page May 23, 2017 · 26 revisions

DEPRECATED IN V4: please use the new framework for this - see here

IXP Manager uses MRTG to poll switches and create traffic graphs for:

  • aggregate (total) traffic over the entire exchange (all infrastructures);
  • aggregate graphs for each infrastructure;
  • aggregate graphs for each switch;
  • aggregate graphs for inter-switch links; and
  • aggregate and per port graphs for each member / customer.

MRTG is particularly efficient in the SNMP sense as, irrespective of how many times an interface is referenced for different graphs, it is only polled once per run.

Please ensure you have configured your port types correctly as discussed in the Port Types section of this page.

Per-second graphs are generated for bits, packets, errors and discards.

Setting Up Your Server for Mrtg Collection

In all cases below, $APPLICATION_PATH is the base directory of your IXP Manager installation.

You need to install some basic packages for MRTG to work - on Ubuntu for example, install:

apt-get install libconfig-general-perl libnetaddr-ip-perl mrtg

You also need a folder to store all MRTG files. For example:

mkdir -p /srv/mrtg
mkdir -p /srv/mrtg/members

In your application.ini, you need to set two parameters:

;; destination for all MRTG output (log files, pngs, etc)
mrtg.conf.workdir = '/srv/mrtg'
;; destintation file for the MRTG configuration. If not set, the generator sends it to stdout
mrtg.conf.dstfile = '/etc/mrtg/mrtg.cfg'

Note that workdir is the same directory you created above (e.g. /srv/mrtg).

You can now generate a MRTG configuration by executing a command such as:

APPLICATION_PATH/bin/ixptool.php -a statistics-cli.gen-mrtg-conf

However, you need to complete additional actions from the Integrating with IXP Manager section below.

You also need to set up a cron job to regenerate the configuration periodically (see below). Note that our header template starts MRTG as a daemon (see below also).

Daemonising MRTG

On FreeBSD, MRTG comes with an initd script by default and you can kick it off on boot with something like the following in rc.conf:


However, on Ubuntu it does not but it comes with a /etc/cron.d/mrtg file which kicks it off every five minutes (it will daemonise the first time and further cron jobs will have no effect). If you use this method, you will need to have your periodic update script restart / stop the daemon when the configuration changes.

To start and stop it via standard initd scripts on Ubuntu, use an initd script such as this (source):

cp $APPLICATION_PATH/tools/runtime/mrtg/ubuntu-mrtg-initd /etc/init.d/mrtg
chmod +x /etc/init.d/mrtg
update-rc.d mrtg defaults
/etc/init.d/mrtg start

Remember to disable the default cron job for MRTG on Ubuntu!

Periodic Updating of MRTG Config

You will need to update your MRTG configuration regularly so any changes made to member ports will be reflected. To do this, create or update your periodic update script (e.g. /usr/local/bin/

#! /bin/sh


# Synchronise configuration files
${APPLICATION_PATH}/bin/ixptool.php -a statistics-cli.gen-mrtg-conf

# Kick daemons
/etc/init.d/mrtg restart > /dev/null

Add the above script to cron to execute a few times a day (or as appropriate for your IXP).

Customising the Configuration

If you wish to change aspects of the configuration, copy the file(s) you wish to change from the APPLICATION_PATH/views/statistics-cli/mrtg directory to the same location under your own skin.

We've made these files very modular so, if you need to change them, you should only really need to change one or too. There are also empty files called:

  • custom-header.cfg
  • custom-footer.cfg

which are included just after the header and at the very end respectively. Skinning these will allow you to easily drop additional content into your MRTG configuration.

Integrating with IXP Manager

Member / customer graphing will work immediately with one configuration option in the IXP table of the database. In the example above, our workdir was /srv/mrtg and so the configuration option you need is to set the mrtg_path of your IXP in the ixp table as follows:

UPDATE `ixp` SET `mrtg_path` = '/srv/mrtg';

If you are using the multi-IXP environment, you can set the above in the frontend under the IXP's menu option - and, in a multi-IXP environment, you will need to set it per IXP. If you are in single-IXP mode, you can find a link to edit the IXP under the Infrastructres page.

That's it! If you want to use a separate server for collecting and generating the graphs, you can make this workdir available over HTTP/HTTPS (secured access by only the web server's IP of course!) and use a configuration option such as the following in place of `/srv/mrtg':

This is possible as graphs are read using readfile().

Aggregate IXP and Infrastructure Graphs

The MRTG script creates aggregate graphs for the entire IXP as well as per-infrastructure graphs. These are named as per the Aggregate Graph Name defined in IXP Manager for each IXP and infrastructure.

These graphs are available from the Statistics menu under Overall Peering Graphs. Also, the graphs on the admin dashboard are the monthly versions of these and will appear on the dashboard when configured as above.

Switch Aggregate Graphs

These are defined and built automatically from the switches you have defined. These graphs are the aggregate of all switch ports (not just peering ports) - which, if you think about it, makes sense as core ports do need to be included here. These graphs are available from the Statistics menu under Switch Aggregate Graphs.

Inter-Switch / Trunk Graphs

The above will generate graphs for all your customer ports and aggregate graphs for all items mentioned at the start of this page except inter-switch graphs. There is currently really no way to be able to create a sane definition of these in the IXP Manager database, so we chicken out and let each IXP do it manually. Simplicity r00lz.

Skin the trunks.cfg file as we have done as a working / production example here.

Once you have defined your own trunks as described above, then add a configuration line such as the following for each to application/configs/application.ini:

mrtg.trunk_graphs[] = "ixpid::core-sw1-sw2-lan1::PoP 1 to PoP 2 (LAN1)"
mrtg.trunk_graphs[] = "ixpid::core-sw1-sw3-lan1::PoP 1 to PoP 3 (LAN1)"


  • ixpid is the ID (from the database table ixp) of the IXP where these graphs reside. In a single-IXP environment (i.e. you have not enabled multi-IXP), this will always be 1;
  • core-sw1-sw2-lan1 is the name as defined in mrtg.cfg.template; and
  • PoP 1 to PoP 2 (LAN1) is the title used on the frontend.

We've included matching sample mrtg.trunk_graphs in our skinned file above.

These graphs will be available in the Statistics menu under Inter-Switch / PoP Graphs.

Inserting Traffic Data Into the Database

There is a database table called traffic_daily which stores the daily / weekly / monthly / yearly average / max / total traffic in / out for bits / packets / errors and discards.

This table is very useful and is used, for example, for generating alert emails based on port utilisation, unusual traffic deltas, etc.

To have this information stored (which is gathered from the MRTG log files), put something like the following in your cron:

0 2     * * *   root    $APPLICATION_PATH/bin/ixptool.php -a statistics-cli.upload-traffic-stats-to-db
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.