How to Install and Configure MRTG on Ubuntu Server

(20161025 – The software versions used in this post were updated — iceflatline)

(20150902 – The steps and script in this post were amended to remove logging — iceflatline)

This post will describe how to install and configure Tobi Oetiker’s MRTG (Multi Router Traffic Grapher) on your Ubuntu server. All steps assume that the Apache http server is installed and operating correctly. Once configured, you’ll be able to use MRTG to monitor the traffic in and out of your network using the SNMP capability in your network’s gateway\router. MRTG generates static HTML pages containing PNG images which provide a visual representation of this traffic. MRTG typically produces daily, weekly, monthly, and yearly graphs. MRTG is written in perl and works on Unix/Linux as well as Windows. MRTG is free software licensed under the GNU GPL.

Software versions used in this post were as follows:

  • Ubuntu Server v16.04.1 x64 LTS)
  • mrtg v2.17.4-3ubuntu1

So, let’s get started.

Download and Install

First, update your package list:

Then download and install MRTG:

If this is the first time installing MRTG on your server you’ll likely be presented with the following message (See Figure 1). Answering “Yes” means that the MRTG configuration file will not be readable by others (file permissions set to 640). Answering “No” means that the file is readable by others (file permissions set to 644). In this example we’re going to accept the default Yes.

Screenshot showing install message regarding MRTG file permissions

Figure 1

MRTG installs a sample configuration file /etc/mrtg.cfg used to hold the SNMP information obtained from your gateway\router. For a full listing of what MRTG installs and where, run the locate command:

Technically speaking, mrtg.cfg could remain in /etc, but just to keep things tidy let’s create a directory for it and move it into that directory:

That’s it for installing MRTG. Now let’s move on and configure it.

Configure

MRTG includes a script called cfgmaker that will help us populate /etc/mrtg/mrtg.cfg with the information obtained from your gateway\router. But before you run cfgmaker, you should setup the SNMP service in your gateway\router. This usually involves logging into your gateway\router and enabling SNMP. The default SNMP community name is typically “public.” If you change the SNMP community name to something else, make note of it. Now, run the following command, substituting your SNMP community name, if you’ve changed it, and adding the IP address of your gateway\router:

If you would like to add more than one gateway\router to MRTG simply append the additional URL(s) to the same mrtg.cfg file. Then, when you build the web page using the indexmaker command described below, all the gateway\routers (and their associated graphs) will be displayed on the same HTML page.

Next, open /etc/mrtg/mrtg.cfg and make sure under Global Configuration Options that the lines “WorkDir: /var/www/mrtg” (under Debian), and “Options[_]: growright, bits” (under Global Defaults) are uncommented. Finally, add the following lines to the existing line EnableIPv6: no under the Global Defaults section:

What does all this do? The line RunAsDaemon: Yes will enable MRTG to…um… run as a daemon. This is beneficial because MRTG is launched only once, thus the parsing of the /etc/mrtg/mrtg.cfg file is done only once, not repeatedly as would be the case if one were to run MRTG as a cron task – another acceptable method for running MRTG. Also, when running as a daemon, MRTG itself is responsible for timing the measurement intervals; therefore, we need to add the Interval line option and assign it a value – in this example 5. This means that every five minutes MRTG will poll the SNMP service in your gateway\router and update its graphs. Finally, since many gateway\routers do not currently support SNMP over IPv6, we’ll retain the line EnableIPv6: no.

Speaking of graphs, by default MRTG graphs grow to the left, so by adding the option “growright” the direction of the traffic visible in MRTG’s graphs flips causing the current time to be at the right edge of the graph and the history values to the left. We’ve also chosen the “bits” option, which means that the monitored traffic values obtained from your gateway\router are multiplied by 8 and displayed bits per second instead of bytes per second.

Okay, now it’s time to create the web pages which display the MRTG graphs using the indexmaker command. Run the following commands:

Open /etc/apache2/apache2.conf and add the following lines in the section containing similar Directory directives:

Then restart Apache:

When restarting Apache you may receive a warning concerning its inability to “…reliably determine the server’s fully qualified domain name…” This non-critical error can be fixed by adding the following line to /etc/apache2/apache2.conf:

MRTG has been configured. Let’s start it up and see what it displays.

Start

There’s something important to keep in mind when starting MRTG, and that is that MRTG requires the environmental variable “LANG” to be C in order to run properly. Since most Linux systems these days, including Ubuntu server, use UTF-8 (run echo $LANG to see what your system uses), let’s change LANG to C and start MRTG using the following command:

When you run MRTG for the first time you may see a lot of complaints about missing log files. No worries, this is normal for the first 2-3 times you start MRTG this way. If, however, it continues to complain you may want to look into the source of the problem.

Well, that’s it. Now point your browser to http://your-server-address/mrtg and you should see a page that resembles Figure 2. You may have more or less graphs depending on the number of interfaces reported by your gateway\router(s).

Screenshot showing the default MRTG web page

Figure 2

Because of the aforementioned option in /etc/mrtg/mrtg.cfg, you’ll see the graph starting “grow” to the right as the traffic is monitored over time, and the Y axis displayed as bits per second. If you click on any one of these graphs you’ll be taken to another page showing individual graphs for 30 minute, two hour, and daily averages, along with the maximum, average, and current bit rate in and out of that particular interface. Only interested in displaying one particular interface? Want to graph other SNMP data? No worries, just remember to run indexmaker again to update the MRTG index.html file.

Okay, so now that we have MRTG installed, configured and running let’s move on and discuss how to keep it running.

Operate

Starting MRTG by hand is not ideal in the long run. So perhaps after you’ve done some tweaking on MRTG and are satisfied with the results, you can automate the process of running MRTG by using a startup script in your system startup sequence. Here’s the script that I use:

To use the script, save it to your home directory as mrtg and make it executable. Then move or copy it to /etc/init.d:

Now, link the mrtg script to all of Ubuntu server’s multi-user run levels (2-5):

Now, let’s start MRTG using our script. If it’s currently running then substitute restart for start in the following command:

That’s it. Now if for some reason your server is rebooted, MRTG should fire up automatically. If you would like to remove the MRTG script from the server’s multi-user run levels, use the command sudo update-rc.d -f mrtg remove).

Conclusion

This concludes the post on how to install and configure MRTG on Ubuntu server. As you can see, MRTG isn’t terribly complicated and proves to be a really nice open source package for monitoring and displaying traffic in and out your network from virtually anywhere you have a web browser. For a full list of all the configuration options and other information I encourage you to visit the MRTG web site.

References

http://oss.oetiker.ch/mrtg/doc/index.en.html

Comments

  1. Thanks for this great write-up! I am using your startup script, and I think it’s great. I did have some trouble finding the RDDs.pm tool, but a quick “apt-get install librrds-perl” fixed everything!

  2. Fantastic. THanks very much :)
    combing Google for hours looking for a good tutorial. As a new linux user I’ve found this was the only one that could lead me to get it working :)

    And that script is fantastic, before that I wasn’t sure how to stop and start it!!!
    Cheers.

  3. HI, thats great , but I’ve problem with this startup script, after Ubuntu bootup it’s telling me: /etc/rc2.d/S99mrtg: 49: –daemon: not found
    And it’s not starup with Ununtu, only manual starup

  4. ask123, there are a couple of things you might check:

    Make sure that the mrtg.cfg file contains the “RunAsDaemon: yes” line under Global Defaults section;

    make sure the script reflects accurately the locations of the directories and files where you’ve set up MRTG;

    make sure the symbolic links to the script from /etc/rc2.d are correct (you might also make sure the server is starting up in run level 2);

    make sure the mrtg script under /etc/init.d is set is set to be executable by owner, group and other; and finally,

    make sure that mrtg.pid file is being written to /var/run.

    If for some reason these steps don’t get you running, then you might trying running MRTG under cron.

  5. noobie, thanks for your comment. I assume you mean password protection for MRTG? I have no plans but perhaps the developer does. You may want to post your question to them directly. However, if all you’re interested in is protecting access to the MRTG page(s) themselves you might consider using a simple approach like an .htaccess file in the MRTG folder root.

  6. @noobie
    You could use an .htaccess in your /var/www/mrtg and setup user/password with the Apache’s “htpasswd” utility, that’s how i password protected mrtg stats on my dedicated server.

  7. Just wanted to let you know, your guide is great. Wish some of the others put this very simple procedure so simply. Short, sweet and to the point.

    Thanks from Albany, NY

  8. Many thanks iceflatline. It’s very helpful for me. I am from IRAQ BAGHDAD. I think nobody like me. But still I like my country, any way I need to ask you, how can I add more than 2 routers. I have 2 dedicated comtech VSAT modems and I need to check there traffic from my end.

    Regards

    Ammar

  9. Ammar, no worries my friend, not all Americans are the same. You are certainly welcome here. Thanks for taking the time to post, and for your question.

    It’s quite easy to add other SNMP devices. Simply append the additional URL to the cfgmaker command described above, like this:

    [text light=”true”]
    sudo cfgmaker –output /etc/mrtg/mrtg.cfg public@your-router’s-IP-address public@your-router’s-IP-address
    [/text]

    See http://oss.oetiker.ch/mrtg/doc/cfgmaker.en.html

  10. IceFaltline ,

    Really I am very grateful to you for your cooperation with me.

    Do you have any idea about how to configure the mrtg on windows?

    Regards
    Ammar

  11. Ammar, no problem.

    Purportedly Windows is supported, although I have not tried to install it myself. See this article at the MRTG web site.

  12. Ammar, it works a little differently under Windows. First make sure you have followed all the steps called for in the MRTG documentation. Then, run perl mrtg .cfg from your ~:\mrtg\bin directory. Let it run for 5-10 minutes to collect data, then run the command again. Navigate to the WorkDir you created when using cfgmaker and you should find a html file there with the results.

    This other guide may be helpful for you too.

    Good luck!

  13. First thanks for this nice tutorial!

    I was trying to create mrtg for localhost machine, but having following error. Need some suggestion.

    cfgmaker –output /etc/mrtg/mrtg.cfg public@localhost

    indexmaker –output=/var/www/mrtg/index.html /etc/mrtg/mrtg.cfg
    Use of uninitialized value $first in hash element at /usr/bin/indexmaker line 353

  14. Iqbal, I’ve not encountered that error before. The fact that you’re using “localhost” as the address suggests that you’re attempting to gather information from the same host you’re installing MRTG on? Perhaps the SNMP daemon in that host is mis-configured? Anyway, a bit of googling on the error suggests this guide may help: http://www.my-guides.net/en/content/view/23/26/.

    Good luck and please post again when you’ve resolved it so others may benefit.

  15. Hi, thank you very much for sharing this information, I’m having problems at the point to see the page, I’m pointing my browser to http://my-ip-address/mrtg but I get a problem loading page, can you please tell me what I’m doing wrong?

  16. supernoob, thanks for posting your question. In that step I did not intend for you to literally use the URL “http://your-server-address/mrtg”. My intent there was for you to fill in the actual IP address of your server. So, you should be using something like http://192.168.1.2/mrtg or whatever your IP address happens to be for your Apache web server.

    My apologies for the confusion.

  17. Thank you very much for your reply and support, I did point it to the IP address of the host where I installed the software, I followed all the steps and I see data already pulled from the device if I edit the mrtg.cfg file, however when I tried to load the page I get the error, I was planning to try today maybe I haven’t enable apache on my ubuntu box, I’m completely new to Ubuntu also. Do you think that can be the case?

  18. iceflatline I really appreciate the work you have done here, I got it to work. I was missing the apache installation and after that it worked perfectly!! Thank you.

  19. supernoob, yup, that would certainly be a problem! I’m glad you got it running. Thanks for posting back.

  20. Thx for this very detailed tutorial… I’m also stuck on the error :

    “Use of uninitialized value $first in hash element at /usr/bin/indexmaker line 353.”

    The link that you have provided above doesn’t give me hint for a possible solution. What do you mean with : “perhaps the SNMP server in the host is mis-configured?”

  21. Thanks for the totorial…….but i encountered a following error……..

    I am trying to install mrtg….i am in the last step in completing the process but when i entered the command..
    indexmaker –output=/var/www/mrtg/index.html /etc/mrtg/mrtg.cfg
    it gives the following error.
    Use of uninitialized value $first in hash element at /usr/bin/indexmaker line 353.

    I searched it on google but i don’t get the proper answer..plz help me out..

  22. I have run through the steps discussed in the post, installing MRTG on Ubuntu Server v10.04 LTS (x64), and polling a gateway at 192.168.10.1 with a SNMP community string of “public.” This setup worked fine and I encountered no errors when configuring MRTG. I would suggest making sure that SNMP daemon in the device your trying to poll is setup correctly and that you are using the correct URL and SNMP community string (typically “public”).

  23. Wow, Thanks a lot coz I was struggled with this for few days with windows and now its working nicely. Thanks again.. ;)

  24. thank you very much for the guide.
    I was breaking my head yesterday both from the Tobi Oetiker’s and others to understand how to install mrtg.
    This morning I’ve found your site and the solution to my problems.
    I’ve successfully installed, configured and started mrtg.
    Really thanks!
    Greetings from Italy! :)

  25. thank you so much for the easy to follow guide. i encountered a problem though. i followed the procedure carefully but the graph failed to start. here what shows up after i put “http://ipa.ddr.ess/mrtg/” in the browser:

    Not Found

    The requested URL /mrtg/ was not found on this server.
    Apache/2.2.14 (Ubuntu) Server at ipa.ddr.ess Port 80

    Below what happens in the cli when I execute “mrtg”:

    katsumoto@ubentoboxx:~$ mrtg
    ———————————————————————–
    ERROR: Mrtg will most likely not work properly when the environment
    variable LANG is set to UTF-8. Please run mrtg in an environment
    where this is not the case. Try the following command to start:

    env LANG=C /usr/bin/mrtg
    ———————————————————————–
    katsumoto@ubentoboxx:~$
    katsumoto@ubentoboxx:~$

    I did try to execute “sudo env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg” a couple of times though hoping to clear the error. Any help is appreciated.

  26. katsumoto, sorry you’re encountered difficulties. It appears MRTG isn’t starting for you. You can use ps -e | grep mrtg to confirm. What version of Ubuntu server did you use? Is it possible that MRTG did not get installed at /usr/bin/ or its config file at /etc/mrtg/mrtg.cfg?

  27. this is my Ubuntu server version:

    Linux 2.6.32-33-generic-pae #70-Ubuntu SMP i686 GNU/Linux
    Ubuntu 10.04.2 LTS

    the daemon is running and MRTG is properly installed at /usr/bin/ and config file looks good a /etc/mrtg/mrtg.cfg though

  28. katsumoto, thanks. I am running 10.04.3 and it seems to work fine for me as of a few minutes ago. Are you sure that mrtg is running? If so, it’s unclear to me why you would be getting that error.

  29. ERROR: Creating templock /var/lock/mrtg/_etc_mrtg_mrtg.cfg_l_1688: No such file or directory at /usr/bin/mrtg line 1833.

    I installed after your steps first mrtg working good but after use your script is not working where is the problem. I dont have installed mrtg in /var/lock/mrtg ????

  30. MrtgProblem, when MRTG starts it creates two files: /etc/mrtg/mrtg.pid and /var/lock/mrtg/_etc_mrtg_mrtg.cfg_l. Remove these two files and/or any other *.pid or *.cfg files that may be contained within these those two directories, then start MRTG manually using [bash light=”true”]sudo env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg [/bash] and verify it works. If it does, then run [bash light=”true”] sudo killall mrtg[/bash] to stop it and then start it again using the script [bash light=”true”]sudo /etc/init.d/mrtg start[/bash]

  31. MrtgProblem, sorry you’re having problems. I have not encountered that error before and I verified today that the steps as written do work on both Ubuntu Server v10.04.3 x64 and v11.04 x64.

    Which version of Ubuntu Server are you using? Are you saying that MRTG will start if you use the command sudo env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg, but not if you use the script?

  32. if i want start mrtg
    sudo env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg
    [sudo] password for black:
    2011-08-04 09:40:23: ERROR: Creating templock /var/lock/mrtg/_etc_mrtg_mrtg.cfg_l_5603: No such file or directory at /usr/bin/mrtg line 1833.

    it not working mrtg stop working after use your script and reboot machine
    use UBUNTU 10.04.3

  33. MrtgProblem, my inelegant advice at this point would be to completely uninstall MRTG from your system and start over. Make sure to use the search tool of your choice to find and delete any leftovers (e.g. /var/log/mrtg and /var/www/mrtg). Another thing to keep in mind when/if reinstalling is there is no requirement to run the script. You could simply start MRTG manually or run it under cron. Good luck and I hope you get it running.

  34. if i reinstall mrtg ist working but after install your script its down, i must try with cron ;) ok thx

  35. Wow. really a very appreciated work man…
    Now i want to one things more…i got mrtg graph of my router Fast ethernet port 1 to 4 but Can u suggest me how can i fetch the particular IP’s usage used on ether3 interface which are on vlan.

  36. Hi Iceflatline, thank you very. This is the best MRTG reference I’ve seen on the net. It works like a charm on a single router. Now, I have a quick question. How would I setup a MRTG to monitor about 80 routers? I have seen your suggestion using the script below for 2 routers but I don’t think it is the best solution for my scenario.

    sudo cfgmaker –output /etc/mrtg/mrtg.cfg public@your-router’s-IP-address public@your-router’s-IP-address

    Any suggestion is highly appreciated.

    Thanks again.

  37. ern, thanks for your kind words.

    ~80! That’s quite a few, and I’m afraid beyond my practical experiences so far with MRTG. Doing a quick Google search on mrtg+support+multiple+routers, however, suggests there are at least a few threads out there with people discussing how they have approached this level of scaling.

    Good luck and please post back when/if you discover an approach that works for you. I would be interested in knowing.

  38. Thanks for this helpful post,

    i successfully installed and am running MRTG as of right now, i am a beginner at this and still cannot integrate other devices in it, i tried the (sudo cfgmaker –output /etc/mrtg/mrtg.cfg public@your-router’s-IP-address public@your-router’s-IP-address) command but for some reason i cannot add, can you please show how to refresh the page automatically

    thanks

  39. Has9, my apologies for the delay in responding. The command should work, but make sure the IP addresses are unique. This article and the MRTG page on cfgmaker both have some examples that may be of help.

    Once MRTG is started the page should refresh automatically every five minutes; however, this can be modified by changing the value assigned to the global configuration option Interval from 5 to some other value.

  40. Hi iceflatline..

    Thanks for this helpful article..i really admired your hard work in writing it..

    I have some basic questions to ask..do we have to install first the SNMP & HTTP before proceed with this MRTG tutorial? Do you have any good links to work it on?..since i already stumble upon different version of configuration on the internet but does know which one to choose..

    Thanks in advance =)

  41. wale89, thank you. You do need to have the SNMP process already up and running in your router, or whatever device you happen to be interested in acquire data from, else the cfgmaker command will return an error. You should also have an http server installed before running the indexmaker command.

    I’m not aware of any links you could simply point your MRTG implementation to.

  42. Hey iceflatline,

    just performed a test (ubuntu) and a production (debian) install following your tutorial: everything went veeery smooth.
    Supercool, thanks a ton!
    I’ve only added a very simple timer contdown (abt. 5 lines) to the page, which I believe would be a useful feature for indexmaker to have.

    Cheers,
    rash*

  43. rashmani, awesome. Glad it worked well for you. The countdown timer does sound useful. Would you mind posting the code when time permits? Thanks!

  44. Dear iceflatline,

    i installed and configure as it is in tutorial but my graph was not updating showing 17mbps and was not updatingg,,, any sugetions

  45. bhargavi, I’m not sure. Assuming you’ve followed the instructions correctly, it should update every 5 minutes. I would suggest going back over the instructions making sure each step is followed. I’ve installed MRTG many times as described and it has not failed to work.

  46. Hello. Thanks for the excellent guide. When using your startup script I get the following:

    root@apollo:/etc/init.d# update-rc.d mrtg defaults
    update-rc.d: warning: /etc/init.d/mrtg missing LSB keyword ‘required-start’

    update-rc.d: warning: /etc/init.d/mrtg missing LSB keyword ‘required-stop’

    update-rc.d: warning: /etc/init.d/mrtg missing LSB keyword ‘default-start’

    update-rc.d: warning: /etc/init.d/mrtg missing LSB keyword ‘default-stop’

    Adding system startup for /etc/init.d/mrtg …
    /etc/rc0.d/K20mrtg -> ../init.d/mrtg
    /etc/rc1.d/K20mrtg -> ../init.d/mrtg
    /etc/rc6.d/K20mrtg -> ../init.d/mrtg
    /etc/rc2.d/S20mrtg -> ../init.d/mrtg
    /etc/rc3.d/S20mrtg -> ../init.d/mrtg
    /etc/rc4.d/S20mrtg -> ../init.d/mrtg
    /etc/rc5.d/S20mrtg -> ../init.d/mrtg
    root@apollo:/etc/init.d# /etc/init.d/mrtg status
    /etc/init.d/mrtg: 73: Syntax error: word unexpected

    Any thoughts? (Ubuntu 10.04.3 LTS )

  47. Andrew: It appears you’ve got something wrong with the script you’re using to start/stop/restart MRTG. If you’re using the one provided in the post it should work as is – I’ve used it many times. If you’ve modified it or are using something else, I would suggest going back over it to make sure it’s coded correctly.

  48. Ice – I found the problem… a few lines concatenated at the end instead of needed line breaks. However, once that’s fixed, trying to start mrtg via the script gives me a permission denied. The script is owned by root, executable, and the mrtg binary is owned by root. I can start it just fine without the script with “env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg –logging /var/log/mrtg.log”.

  49. I’ll do more checking, I have a feeling there be other problems in copying the file… thanks again for the article.

  50. Andrew: Thanks for your kind comments and taking the time to post. I’m glad it’s working for you.

  51. for people getting the 353 error, “Use of uninitialized value $first in hash element at /usr/bin/indexmaker line 353”, the cause is an empty list created by your cfgmaker. if you are writing a file for each device and you have probably forgot to include those files in the main mrtg.cfg.

  52. Thanks man
    its great !!!!
    I was curious to know if there is any way to get live graphs like what we have in dd-wrt ?

  53. This is great! thanks for the help….. however if I want to have multiple devices… I realize i can make multiple config files, but how do I add multiple routes and graphs… thanks again.

  54. tony, thanks for your comment. Actually, the way I would do it is not create multiple MRTG configuration files, but rather append the additional router URLs to the same mrtg.cfg file using the cfgmaker command, like this:

    [text light=”true”]
    sudo cfgmaker –output /etc/mrtg/mrtg.cfg public@the-first-router’s-IP-address public@the-second-router’s-IP-address
    [/text]

    Then when you build the web page using the indexmaker command, all the routers (and their associated graphs) will be displayed.

    See http://oss.oetiker.ch/mrtg/doc/cfgmaker.en.html

  55. I’m pulling up the mrtg page: http://myipaddress/mrtg

    but I only see:

    MRTG Index Page

    MRTG Multi Router Traffic Grapher
    version 2.16.2 Tobias Oetiker and Dave Rand

    No graphs!

    I see the page is refreshed every 5 minutes,. but only shows the header and footer. There are no graphs showing (not even placeholders for the graph boxes).

    1. I missed the step of installing the snmpd.
    So I added the following:

    sudo apt-get install snmpd

    That installed successfully.
    However, do I need to make any changes in any of the snmpd.conf files?
    This is a plain vanilla ubuntu server installation.
    The target is the ‘localhost’ itself, to monitor it’s own traffic.

    However, I still get an MRTG page that has only header and footer, but no graphs.
    What else am I missing?

    Thanks,

    -Sup.

  56. SupermanInNY, I would try creating the mrtg.cfg file against a device with a known good snmp daemon running first, say like a router or switch, if you have one. If that configuration works then start looking at the SNMP configuration in the your Ubuntu server. You may also want to consider using an IP address – 127.0.0.1 or the LAN address of the interface – instead of “localhost.”

  57. My problem now is that I’m not familiar with SNMPd setups. I usually have a linux box with DirectAdmin (control panel) and there is a quick install setup file that runs, installs and configure MRTG automatically with no SNMP service at all.

    Since I don’t care for anything other than Network traffic,. is there a quick snmp config file that I can use?

    thanks,

    -Sup.

  58. SupermanInNY, apologies, I don’t have a “quick snmp config” for you. A quick google search, however, suggests their are instructions a plenty out there on how to configure SNMP on Linux, including Ubuntu server. Perhaps one of these will prove helpful for your particular configuration.

  59. Thanks.
    I ended up droping the VPS setup, and installing a clean slate VPS with DirectAdmin as the control panel and then installed the custom MRTG for it. One of the steps there required me to install libgd:

    sudo apt-get install libgd2-xpm-dev

    Perhaps that was the missing step,. but in any event, I dropped that vps instance,. so I can’t trace back what I missed.

    Thanks,. I’m now using the DirectAdmin custom install.

    -Sup.

  60. Thank you for the gret write up. With this and the saved html files from the original tweaking prior to rebuilding my server, the installation and configuration of my new mrtg install was so fast my sandwich from that fast place never got bitten into.

  61. Hi, nice write up. It was ages since i last configured myself MRTG – as i now use CACTI – and i was totally lost.

  62. Thanks Pocopico. It’s been awhile since I’ve used it as well. Elected instead to use the RRD graphs contained within my gateway/router.

  63. Question! anyone have problem with interface 1 gig and over reporting incorectly? we have a few 10 GIG interfaces that seems to be report incorrectly…. is there a fix for this?
    thanks

  64. tony, thanks for posting the question. Could you elaborate a little more on what you mean by “reporting incorrectly?” Is it not reporting at all, some scaling issue, or something else?

  65. scaling issue….. thanks for respond…….. it is reporting, but the amount of traffic is incorrect.. thanks for your help.

  66. Hello. Very nice of you to compile this guide. I have been running mrtg on openSuSE servers for years and I have recently started using Ubuntu server without any gui install to economize on resources for monitoring network perfomance (throughput). I have always been using cron calling on mrtg with multiple configuration files and I feel comfortable with that. It alll works at it always has but no mail ever arrives anymore on the root local mailbox (it used to do that with mrtg on opensuse). From what I managed to find out, root does not receive regular mail on ubuntu like it works in OpenSuSE. I realize I can probably forward mail with postfix to an external account (like I do with my nagios machines on ubuntu servers) but I really want to keep that approach where every mrtg machine is contained and I check mail localy.
    Have you already met that problem? How are you dealing with it?
    Also I have tried messing around with using RRD with MRTG in order to create graphs on demand, so I can reduce load on the mrtg machines which work constantly to create the graph image files. I managed to do what I wanted with only one graph but nothing like what I had (Ι have a website with html tree based organization, branches leading to specific network nodes where every network port is monitored). I have tried Steve Shipway’s approach (Routers 2) but the menus are really unattractive. Have you tried using or created anything like that?
    Keep up the good work!
    In my company I am using MRTG for network throughput, Smokeping for delay, jitter, loss, and Nagios for server and process monitoring.
    Yannis

  67. Yannis, thanks for the kind words. I have not used MRTG on Ubuntu in some time; electing instead to use the RRD features native to the pfSense firewall I am running. Aside from some very minor quirks, RDD is well supported in pfSense.

    When I did operate MRTG on Ubuntu I usually ran it as a daemon and not from cron so I never encountered the lack of mail problem you’ve described. As you suggest though, you’ll likely need to look deeper into why the mail is not sent after cron jobs are run. Do other cron jobs get mailed?

  68. I am guessing anything mailing anything to root@localhost will not be delivered anywhere, unless you redirect root’s mail to a specific account, local or remote. I working on that hypothesis and trying to find out more, in the mean time I am very nostalgic of my OpenSuSE installations.

  69. Pingback: Nagios and MRTG
  70. hi, i need help please
    i can not run the script

    sudo /etc/init.d/mrtg start = command not found

    please help

  71. parvez, I just tested the script again and it works fine for me under Ubuntu server (x64) 12.04 LTS. Did you make the script executable and correctly copy it to the appropriate run levels? Does it start it using the command sudo env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg?

  72. Hi…thanks for the awesome tutorial. I ran into this problem:
    –base: Get Device Info on public@192.168.1.74:
    SNMP Error:
    no response received
    SNMPv1_Session (remote host: “192.168.1.74” [192.168.1.74].161)
    community: “public”
    request ID: 973983866
    PDU bufsize: 8000 bytes
    timeout: 2s
    retries: 5
    backoff: 1)
    at /usr/share/perl5/SNMP_util.pm line 629
    SNMPWALK Problem for 1.3.6.1.2.1.1 on public@192.168.1.74::::::v4only
    at /usr/bin/cfgmaker line 960
    WARNING: Skipping public@192.168.1.74: as no info could be retrieved

    Use of uninitialized value $comment_sysdescr in substitution (s///) at /usr/bin/cfgmaker line 384.
    Use of uninitialized value $sysname in concatenation (.) or string at /usr/bin/cfgmaker line 417.
    Use of uninitialized value $comment_sysdescr in concatenation (.) or string at /usr/bin/cfgmaker line 417.
    Use of uninitialized value $syscontact in concatenation (.) or string at /usr/bin/cfgmaker line 417.
    Use of uninitialized value $syslocation in concatenation (.) or string at /usr/bin/cfgmaker line 417.
    –base: Writing /etc/mrtg/mrtg.cfg

    I downloaded snmp onto my server and it’s still not working. I’ve read through the comments but didn’t see anyone with a situation close to mine. Can you he;p me out? Also in your instructions it says when using the cfgmaker to use the ipaddress of my router. Then when going to the web page it says ip address to your server. Can I just use my server address for both or does it have to be my actual router ip address?

  73. verb, it appears to me that something in the SNMP implementation in your server may be setup incorrectly. Perhaps you can point MRTG at another device – like a home router with SNMP implemented by the manufacturer – to verify MRTG is configured correctly and then troubleshoot from there. Out of curiosity, you might try forcing cfgmaker to use SNMPv2 to see if your server just isn’t supporting SNMPv1 well. Instructions on how to use that option are located in the cfgmaker documentation at the mrtg web site.

    The IP address can be from any SNMP-manageable device. I used a router in the example, but it was just that, an example.

    Good luck and let me know what you find.

  74. Hi Ice,

    I tried to set up the SNMP on my Ubuntu Server last night; with no success. I can check if my router is running SNMP it’s just your typical ISP provider router. I plan to turn on of my old machines into a router I just haven’t had the time yet.

    Could you possilbe point me to a good, ‘thorough’ SNMP installation configuration site? I’m relatively new to Ubuntu but installation/config. instructions are so vague sometimes. Or they say, so simply set up software xyz and you’ll be fine. But software xyz has about 2 hours worth of installation itself. I tried to set up Nagios and it took me about 5 sets of instructions to get it running. Even then it didn’t do exactly what I wanted it to do.

  75. Verb, excellent. Don’t feel bad, that stuff happens to me all of the time. Thanks very much for posting back and providing the link.

  76. hi, i have an problem,

    root@odee:/home/odee# sudo env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg
    root@odee:/home/odee# sudo /etc/init.d/mrtg
    sudo: /etc/init.d/mrtg: command not found

    mrtg is already at /etc/init.d/ and also is not empty, i checked it already.
    At localhost i see five empty graphs, mrtg can read from my router, device names putted mrtg from my router correctly. Apache, PHP5 and MySql working fine.

    Any ideas? :)

  77. Thank you for a great tutor Mr. Ice. I have problem when try to running command:
    # indexmaker –output=/var/www/mrtg/index.html /etc/mrtg/mrtg.cfg
    ERROR: did not find any matching data in cfg file

    I hope you can give some advise for my error. Thanks.

  78. Bizax, make sure there are two hyphens preceding the output argument in the command, like this:

    [text light=”true”]
    sudo indexmaker –output=/var/www/mrtg/index.html /etc/mrtg/mrtg.cfg
    [/text]

    Also make sure that the mrtg.cfg file does indeed reside in /etc/mrtg.

  79. Thank you for a very nice tutorial. I managed to get it up and running in just a few minutes.
    My question is as follows: if I want to monitor 3 devices, will the startup script accept 3 arguments in DAEMON_ARGS?
    Something like:
    DAEMON_ARGS=”/etc/mrtg/mrtg.cfg /etc/mrtg/mrtg_switch.cfg /etc/mrtg/mrtg_router.cfg”

    thank you in advance.

  80. Liviu, thanks for the comment. I’ve never tried that, but I see no reason why you shouldn’t :) Let me know if it works.

  81. 1. How do you aggregate on MRTG? What are the steps?
    2. I have two PoPs and want to monitor them on the same server,how do i combine them, bcos they are of the same SNMP

  82. Thanks for your quick response, Ice! Can you help me with the aggregation? I believe your answer to this will make me smile ;)

    Thanks.

  83. Hi Ice and all interested, I have a little problem with using MRTG with SNMP in monitoring CPU, Memory, HDD and others OIDs. Your MRTG setup-manual works fine for monitoring LAN, but in Ubuntu Server 12.04 the SNMP have not OID in /usr/share/snmp/mibs but in /usr/share/snmp/mib2c-data. Do you have any experience with monitoring CPU, Memory and others? Thank you :) Luke

  84. Luke, thanks for the comment. I’m afraid I don’t have much experience with MRTG beyond router interrogation. Could it be as simple though as making sure the SNMP process is running in the Ubuntu box and pointing MRTG at the correct URL?

  85. Hi, Iceflatline… I have a problem, I followed your instructions .. when entering the command line:

    indexmaker –output=/var/www/mrtg/index.html /etc/mrtg/mrtg.cfg

    This information appears as

    ERROR: Line 20 (RunAsDaemon: Yes) in CFG file (/ etc / mrtg / mrtg.cfg) does not make sense.

    I tried looking on google but no answer. what should I do?

  86. Now the situation has changed
    when I try the same command line is different but the results will be like this:

    ERROR : did not find any matching data incfg file

    What should i do?

  87. Lihazna,

    Have you checked whether there is indeed any data in /etc/mrtg/mrtg.cfg? If there is not, you might try running the cfgmaker command again, making sure that you have correctly specified the SNMP community name and address of your device.

  88. nice instructions helped me alot.

    but i have on problem. i want to monitor a whole bunch of different switches in my network. and to keep it logical i want to give each switch it’s own config file, i know i can doe it but now i also want to start al these different config files in one go. can i use this script and just add multiple configs/daemons to it or do i need to make it separate for each switch ?

    i was thinking maybe something with a directory filled with all the configs and it reads every config one by one.

  89. sacredrose, thanks for the comment. I honestly don’t know. I’ve not tried the script with multiple configs. I suggest giving it a go and see if it will work. Another option might be to setup a cron job for each config.

    Let me know how you make out.

  90. thanks for the fast reply.
    i searched a bit further and found out that you can’t have multiple configs file run as a daemon. but you can make a master config. this config file runs as the daemon and has includes for all the seperate config files.

    but now i’m having trouble running the script i followed al the steps and if i try to start it it says: -bash: /etc/init.d/mrtg: /bin/sh^M: bad interpreter: No such file or directory

  91. sacredrose, thanks for the update. That makes sense. Regarding the error, open /etc/init.d/mrtg and make sure there are no strange characters in the first line. It should be #!/bin/sh .

  92. ahh sorry i forgot to tell i already fixed it. i created the file on windows and then copied it to the linux server. so the line endings where in a wrong format but it was easy to fix with dos2unix.
    thanks for your awesome help this tutorial and stuff has really been a great help

  93. sacredrose, right, I thought that might be the problem. Glad you got it up and running. Thanks again for your comments.

  94. Hi,

    An excellent article, thankyou.
    I am trying to get MRTG to work with SNMP Version 3 which doesn’t use a community. Just a Username and Password. (MD5). Can you advise if you know where I can locate the correct syntax for this line please, I haver been searching for a few days now :(

    sudo cfgmaker –output=/etc/mrtg/mrtg.cfg public@your-router’s-IP-address

  95. McParty, thanks for commenting.

    Unfortunately I have no experience with SNMPv3; however, it appears from looking at the MRTG cfgmaker documentation, you’ll need to use the –username argument, along with the –authkey or –authpassword arguments, or possibly the –privkey or –privpassword arguments. See the “User-based Security Model Arguments” section of http://oss.oetiker.ch/mrtg/doc/cfgmaker.en.html.

    I hope this helps. Please post back with your solution so others, including me, may benefit.

  96. thank you very much for the contribution …. but I have some questions I hope you can help me.
    After entering the line:
    # sudo indexmaker – output = / var / www / mrtg / index.html / etc / mrtg / mrtg.cfg

    I get the following errors:

    WARNING: “HtmlDir” not specified
    WARNING: “ImageDir” not specified
    Use of uninitialized value in split at / usr/share/perl5/MRTG_lib.pm line 770.
    Use of uninitialized value in split at / usr/share/perl5/MRTG_lib.pm line 771.
    ERROR: Please fix the mistake (s) in your config file
     
    How could I fix this?

  97. jeanpierre, the command you’ve cited appears to contain extra spaces preceeding and following the forward slashes. Try the command again but make sure that you do not have any extra spaces. Also, ensure the output command is immediately preceded with two hyphens. The command should look like this:

    [shell light=”true”]
    sudo indexmaker –output=/var/www/mrtg/index.html /etc/mrtg/mrtg.cfg
    [/shell]

  98. thanks for replying …. but the entry of the line of code is either:

    sudo indexmaker –output=/var/www/mrtg/index.html /etc/mrtg/mrtg.cfg

    and the result is still:

    WARNING: “HtmlDir” not specified
    WARNING: “ImageDir” not specified
    Use of uninitialized value in split at / usr/share/perl5/MRTG_lib.pm line 770.
    Use of uninitialized value in split at / usr/share/perl5/MRTG_lib.pm line 771.
    ERROR: Please fix the mistake (s) in your config file

    I hope you can help me.

  99. jeanpierre, then I’m afraid I don’t know what the cause of those errors are. I’ve not encountered them before. Perhaps start by investigating the lines called out in the error message?

  100. Dear ALL,

    I am trying to install mrtg on ubuntu from many days but still no luck.
    Can any can help to fix this problem.
    indexmaker –output=/var/www/mrtg/index.html /etc/mrtg/mrtg.cfg
    ERROR: did not find any matching data in cfg file

    Please help.

  101. kashif, have you checked whether there is indeed any data in /etc/mrtg/mrtg.cfg? If there is not, you might try running the cfgmaker command again, making sure that you have correctly specified the SNMP community name and address of your device.

  102. Hi Guys,

    Please help me resolve this problem of mine in cgfmaker.

    root@mnladm01:/etc/mrtg# sudo cfgmaker –output /etc/mrtg/mrtg.cfg Fortigate@10.1.7.254
    SNMP Error:
    no response received
    SNMPv1_Session (remote host: “10.1.7.254” [10.1.7.254].161)
    community: “Fortigate”
    request ID: 1179398709
    PDU bufsize: 8000 bytes
    timeout: 2s
    retries: 5
    backoff: 1)
    at /usr/share/perl5/SNMP_util.pm line 629
    SNMPWALK Problem for 1.3.6.1.2.1.1 on Fortigate@10.1.7.254::::::v4only
    at /usr/bin/cfgmaker line 959
    WARNING: Skipping Fortigate@10.1.7.254: as no info could be retrieved

  103. Just followed the instructions and go smoothly..
    Able to use MRTG
    Did not continue to follow the script have to explore more..

    Thanks so much

  104. Hey there, I was hoping you might be able to help troubleshoot this with me… I followed all the steps in your guide to a T except I had to do a sudo mkdir -p /var/www/mrtg to create that dir. After it was all done, I tried to open the page by going to http://192.168.5.230/mrtg (ip of the Ubuntu box on Hyper-V) and I get an “Unable to Connect” error. I also tried from the Ubuntu box using the 192.168.5.230/mrtg, “localhost/mrtg” and the loopback IP, none worked. Any ideas?

  105. bhesterberg,

    Hard to say. Is the MRTG daemon running? Is the http server running? Perhaps directory/file permissions on /var/www/mrtg?

  106. An appropriate representation of the requested resource could not be found on this server. This error was generated by Mod_Security.

  107. basically, I get a Permission denied when I try and run “sudo service mrtg start”
    I don’t see mrtg or http service running, providing they are named “mrtg” and “http” when I run the command “top”

  108. Well, no. Your page didn’t say to install it so I didn’t. My fault I suppose. I’m starting over and installing apache and snmpd before I install mrtg. Sorry for the mistake, told you I was still noobish :-)

  109. bhesterberg, certainly not your fault. I did not clearly identify the need to have a running http server. I made the assumption that users interested in deploying MRTG would already have met that requirement. Assumptions are bad. I will revise to post to indicate the requirement must be met.

  110. This post was amended to indicate the requirement to have a http server installed and running.

  111. bhesterberg, yup, I just tried to implement this on a Ubuntu 14.04 server in a VM and am running into the same problem. I suspect there now needs to be further configuration in the Apache server in order to access the URl. I’ll try to sort this out as soon as I can and report back.

  112. bhesterberg, apparently the latest version of Apache (2.4.7-1ubuntu4) shipping with Ubuntu 14.04 LTS no long allows local sub-directories under the document root without explicit Directory directives. I’ll update the post as soon as possible, but here’s the fix:

    Open /etc/apache2/apache.conf with an editor, and add the following lines near the existing Directory directives (near the middle of the file):

    [text]
    Alias /mrtg "/var/www/mrtg/"

    <Directory "/var/www/mrtg/">
    Options None
    AllowOverride None
    Require all granted
    </Directory>
    [/text]

    Restart Apache:

    [shell light=”true”]
    sudo /etc/init.d/apache2 restart
    [/shell]

  113. ice,

    Really appreciate you taking the time to look into this and working up a fix! I ended up deleting that VM and installing Ubuntu 12.04 instead and got it working that way. I may end up making a new one and using your fix, I like to be on the latest LTS versions. Thanks again!!

  114. bhesterberg, no problem. Thanks for bringing this issue to my attention.

  115. Note: the steps in this post were amended to address changes in recent versions of software, notable Apache. Other minor editorial corrections were also made.

  116. I have just followed every step and everything was working fine until I tried to access the graphs //lx.x.x.x/mrtg and I get this error: The server encountered an internal error or misconfiguration and was unable to complete your request.

    Please contact the server administrator, webmaster@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

    More information about this error may be available in the server error log.

    (I am a newbie to Linux)…please help.

  117. ray-damji, I’m not sure. I assume you’re using Ubuntu Server 14.04? If you’re getting the apache default page when you navigate to x.x.x.x then you’ve likely got a misconfiguration in MRTG. Make sure its daemon is running, review the configuration steps, etc. If you’re not getting that default apache page then apache has a problem. Analyze its error log at /var/log/apache2/error.log to help determine what the problem might be.

  118. Ice,
    I am using Ubuntu desktop 12.04.I actually do get the apache default page.I am gonna review the MRTG configuration steps again and see if I can get right ….nevertheless kindly keep any suggestions coming.

    #the server encountered an internal error or misconfiguration and was unable to complete your request.

    Please contact the server administrator, webmaster@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

    More information about this error may be available in the server error log.#

  119. ray-damji, in that case remove the lines the steps had you add to apache.conf and see if that fixes the problem for you.

  120. Ice,

    boom…….I am basking in happiness because of you……..removing the lines from apache.conf did the trick..Thank you very much,thank you.
    Though now my biggest challenge is gonna be to understand that.Thanks again Ice…..It is working very well

  121. ray-damji, the latest version of Apache (2.4.7-1ubuntu4) shipping with Ubuntu 14.04 LTS no long allows local sub-directories under the document root without those explicit Directory directives. If you upgrade to a later version of Ubuntu, or more specifically, a later version of Apache, you’ll need to remember to add those lines back to apache.conf.

    Anyway, glad it’s working for you…

  122. I want to convert my mrtg to rrdtool. Do you have a similar writeup.
    Thank you for the write up installing mrtg worked well for me.

  123. Simba, with regrets, no. That sounds like a good idea for a future post though. Thank you.

  124. @ Iceflatline, may you please do so. I have installed rrdtool on ubuntu but now stuck and a bit confused on the last bit of getting it to work. Some talk of the cgi.
    Thanks once again. I will be checking your blog for the conversion.

  125. Gugun, when you say the graphs do not appear, do you mean the entire page does not appear, the graphs do not appear, there is no graph activity, or something else?

  126. I was trying the service using your instructions and they worked really well.. Thanks for the instructions.. I have a question, how often the server is going to updates the logs and how to change this settings to check every 15 minutes?

    Thanks

  127. Adrian, thanks for your comments; glad the steps worked for you. The option Interval in the configuration file /etc/mrtg/mrtg.cfg determines how often the graphs are updated (in minutes). I chose 5 minutes, but you could choose 15 instead if desired. Of course, if you’re running mrtg as a cron job then you’ll want to make adjustments in the associated crontab.

  128. I am having an issue with the startup script…. it is giving me an error about Log_daemon_msg: not found. any advise?

  129. bobby, I’ve not encountered that error before. Which version of Ubuntu server are you using? I’ll try to recreate the error.

  130. bobby, apologies for the delay. I just reinstalled MRTG per the instructions on the post on a fresh copy of 14.04.2 LTS running on a VM and I am not encountering that error. It looks like the mrtg daemon is unable to log for some reason. You might try commenting out the DAEMON_ARGS line in the script to see if the problem persists. If it runs correctly, then you’ll need to look into the logging error further.

    Good luck and let me know what you find out.

  131. I am running 14.04 TT. This generally works well. I have a couple of questions that are picky:

    1 is that I queried a Juniper Virtual Chassis with a “ton” of interfaces. Is the only real way to eliminate to 200 or so that are not “critical” because they don’t connect to an ISP, ie, just to edit the index.html?

    Secondly, I don’t understand how to create the subdirectories, if I wanted to have a different device/page.

    Lastly, why are all my graphs now straight lines?

    Thanks

  132. Ryan, thanks for the questions. I’m afraid I don’t have many answers. With respect to reducing the interfaces, editing index.html is certainly one way to do it. But perhaps there is way to filter the interfaces that are included in the SMNP response from the Juniper device. Just a thought.

    As for the straight lines, not sure. But I suspect MRTG is not receiving what thinks is valid interface information to display. Not sure exactly why though.

    As for the separate directories, no clue. Hoping you will figure it out and let me know :)

  133. Thanks! I found that if I just deleted all the files in /var/www/mrtg of the routers in question, then re-ran the commands, all was good.

    Ah, separate directories… will have to look more. Then I will post here!

  134. Thank You! I tried a couple of instillation instructions from different web sites. Was just a wast of time. I’m new at this so that took hours for me. Followed you instructions and was up and running in 40 minutes.

  135. Very well notes on how to install and configure MRTG on a Linux server. I use it to get stats from Cisco devices: it is possible to get the “description” name of each LAN port instead of the anonymous “Fax/y” in the graph title ?
    Thank You

  136. Martino, as far as I know, MRTG will simply display the information it reads from the SNMP counters in the device(s) you’ve pointed it to. It may be that you can configure what MRTG is displaying at the device end. Another option would simply be to edit the index.html file and make the graphic titles display any text you’d like.

  137. How do i achieve a decadely graph like that of Monthly, Yearly , Weekly etc. Please, help me. I need more than 2 years or a decade graph.

    Thanks

  138. You’re a legend. Very helpful for me to setup the MRTG in ubuntu. Very straightforward and brief. i don’t have any issues setting up the MRTG at all. Thanks again.

  139. Thanks for the tutorial I get everything to work .. I was able to see the graphs and updates after 5 minutes. However, I am not getting the right speed on the port.. Port that should be running at 1 GIG the PRTG server populates the table with a max of 125 MB.. Is there any way I can change the max speed to be log on the PRTG mrtg.cfg file.. Any help is appreciated.

  140. Adrian, the MRTG graphs should scale automatically as the bit rate through the interface increases or decreases.

  141. Yes, I am getting all the graphs and they are growing, but the speed on the ports are wrong MRTG is seeing 1 GB ports as Max speed of 125 MBytes.. It should say 1024 MBytes…

  142. Apologies. I misinterpreted your comment. MRTG uses max bytes per second by default. Since 125 * 8 = 1000 Mb/s the graph is reporting correctly, albeit in decimal instead of binary. I just tried it again on my router which has GigE NICs and MRTG is reporting the same. I have not experimented much with MRTG’s cfgmaker so I’m not sure to what extent its defaults can be modified. Further information on cfgmaker and its options can be found at http://oss.oetiker.ch/mrtg/doc/cfgmaker.en.html

  143. Hey not apologies needed! You did a wonderful tutorial.. Thanks for all your help… I will look for more info on the link you listed…

    Thanks again!

  144. Hello, thanks for your response but there are some issues am facing:

    1. I loose all the historical graph whenever there is a incessant power outage though it is healthy but i thought it should continue from where it stopped or refer to its log rather going blank and start afresh.

    2. How can add more switches to the initial setup without loosing any graph of populating from the beginning.
    I have two Foundry switches of 24 ports and each with fast Ethernet and Fibre connected to each with SNMP enabled. I want to add another Foundry Switch without MRTG resetting the graph.

    Thanks!

  145. Charz, I fired up a Ubuntu virtual machine to test this. I let MRTG run for awhile to collect data from a router, then killed the VM for a couple hours. After restarting it all, all graph data was retained, except of course for the period encompassing the “outage.” Not sure what’s happening with your setup.

    With respect to adding additional devices to MRTG that’s doable and covered in the post. Unclear whether doing so will result in loss of existing graph data.

  146. Hi folks. I’ve installed MRTG on Ubuntu running here in the lab. The install is straight out of the book. I followed 2 URLs to install. https://help.ubuntu.com/community/MRTG and and this Page. Basically, they are essentially the same. When I bring up MRTG in IE, I use ‘http:’, there isn’t any /mrtg. This will return ‘page not found’. But, I do get the Traffic Analysis graphs for the SNMP device. If I click on a Graph, I get “Oops! This link appears to be broken”.
    So 2 issues for me here. Both fundamental, I’m sure. Where is the URL /mrtg set? and why the “Oops” message? I’ve read through some help, and looked into index.html, mrtg.cfg, but no joy.
    Any suggestions for me would be much appreciated. I would think that after suing L/Unix for years, I could at least figure this out! -Fred

  147. fredv, thanks for posting your comment. I would start by looking at /etc/apache2/apache.conf and make sure you have the Directory directive setup correctly, as outlined in the post.

  148. Hello! Thanks for the tutorial. It was very helpful.
    But I’m having some troubles with the script… Can you help me?
    I see a error in my debian jessie. “The job mrtg.service failed”. And it give me some instruction to do the details bellow. Some idea?

    root@MRJV50210414:/home/fabiana# systemctl status mrtg.service
    ● mrtg.service – LSB: mrtg init script
    Loaded: loaded (/etc/init.d/mrtg)
    Active: failed (Result: exit-code) since Qua 2015-08-26 09:29:55 BRT; 24s ago
    Process: 4725 ExecStart=/etc/init.d/mrtg start (code=exited, status=203/EXEC)

    Ago 26 09:29:55 MRJV50210414 systemd[4725]: Failed at step EXEC spawning /et…y
    Ago 26 09:29:55 MRJV50210414 systemd[1]: mrtg.service: control process exite…3
    Ago 26 09:29:55 MRJV50210414 systemd[1]: Failed to start LSB: mrtg init script.
    Ago 26 09:29:55 MRJV50210414 systemd[1]: Unit mrtg.service entered failed state.
    Hint: Some lines were ellipsized, use -l to show in full.

  149. Fabiana, I honestly have no idea. I assume ‘Jessie’ uses systemd? I’ve not testing the script in a system using systemd so I’m not sure if it is even usable at all. That said, the system appears to be complaining about LSB so you might try commenting out line 33 in the script to see if that gets it running. If not, you can always abandon the script and run MRTG from cron.

    I’ll try to find some time to do further testing.

  150. Thank you so much for your guide! It works for me. :) But i have a question. do you know how and the codes/commands for mrtg to send alerts via email on Ubuntu? i hope you can help me with this xx

  151. Thank you very much for your wonderful guide.
    I have a question, I remove mrtg from my server and re-install every thing according to your guide. When restarting MRTG, Message says OK . But when executing service mrtg status it display following message.
    * mrtg is not running

    Please help me.

    Thank you!
    Dambar

  152. I’m not sure. Just to test this I reinstalled MRTG using the instructions and it started fine using service mrtg start. When starting correctly you should receive the message “Daemonizing MRTG …” Are you getting this message or something else? You can also check its status using ps -aux | grep mrtg. If it isn’t starting you might check whether the update-rc.d defaults command correctly linked the mrtg script to run level 2. Check /etc/rc2.d/ and you should see a symlink to the mrtg script located in /etc/init.d/mrtg. If you’re not seeing that link then you might try running that command again.

  153. hi iceflatline,
    Thanks for such a nice tutorial it is really very helpful, i followed this tutorial and got everything setup successfully. in mrtg.config i used individual config scripts for each device like
    Include:/etc/mrtg/ip/10.10.0.1.cfg
    Include:/etc/mrtg/ip/10.10.0.2.cfg
    Include:/etc/mrtg/ip/10.10.0.3.cfg

    and so on. And i also set separate output folder for each file, it successfully generated separate graph png and html files for each device.

    The issue is mrtg is updating its log every 15 min but it is not printing correct snmp data, it is printing same values since it is started.

    any idea how can i fix it ???

  154. Bilal, I’m afraid I don’t have any ready answers for you at the moment. I’ve not tried nesting *.cfg files using Include statements like that before. Perhaps try creating one mrtg.cfg file per device as per the instructions and try them one at a time just to make sure mrtg is receiving data from the device and graphing correctly. Assuming that works then move on to nesting one in a config file to see if the problem occurs.

  155. Iceflatline,
    Thank you again for your response. i figured out what was wrong, just restarted snmp service on server and that fixed the issue, and currently i am using nesting for 5400 IPs (O-O) and mrtg is graphing perfectly.
    Now next target is to add about 7500(30 subnets of /24).
    I’ll be in touch.

    Thanks ,
    Bilal

  156. Hi Dude, I need to split the timings from 7 am to 4 pm and 4.30 pm to 1.30 am (next day) in graph. Is it possible?

  157. Ice,

    I’m getting the following error when i run this command.

    sudo service mrtg start
    mrtg: unrecognized service

  158. Hari,

    A couple things you might check:

    1. That mrtg script executable;

    2. That there’s no wierd characters in the script. Sometimes copying the script text from the post introduces strange characters;

    3. Whether the update-rc.d defaults command correctly linked the mrtg script to run level 2. Check /etc/rc2.d/ and you should see a symlink to the mrtg script located in /etc/init.d/mrtg. If you’re not seeing that link then you might try running that command again.

  159. Big thank you for the instructions above. I am monitoring two ASUS RT-N66U routers. I have tweaked with the config file but can’t see how to stop and restart MRTG with the new configs. What am I missing?

  160. Thanks Rob. I’m not sure I understand your question. Is it that you’ve edited mrtg.cfg and now can’t start MRTG?

  161. Hi,

    Thanks for this great tutorial. I’ve set it up and works great. Except for one switch and one port. All other switches are working fine, but the one I’m getting the error message that MRTG data has expired (1222 minutes old). No matter what I do, even start all over again, I can’t get rid of this error. Any ideas?

  162. Edwin, I have not encountered that error before. If I were to guess I would say that MRTG isn’t getting a response from the SNMP service in the switch. Perhaps it’s not running (or not running correctly)?

  163. First, many thanks for your tutorial, it’s very helpful, but it has an error, when you say to modify the file apache.conf, you really mean apache2.conf, I did modify both, firs the apache.conf and it does not work, but, it’s really apache2.conf the file to modify. Thanks a lot for your time and I hope have been helpful too.

  164. Enrique, good catch. Thanks for bringing that to my attention. I’ve changed the post.

  165. fml it worked, im pulling this project throughout whole summer and with your tut ive managed to put
    mrtg online. Much thanks man!

  166. it is so good, but i would like to know how to monitor cpu, memory, hard disk. that is what i canot do until now.
    thanks i hope you help me Sir.

  167. Crimildo, thanks for your comment. I have not used MRTG for monitoring anything other than network traffic so I can’t advise you on how to do it. However, a quick Internet search suggests there are a quite a few tutorials online to help you do just that. You might also check out RRDtool, also written by Tobi Oetiker, the author of MRTG. Here again there appear to be many tutorials online to help guide you.

  168. Wow bro, very nice tutorial. I didn’t actually get it to work, but I think you spent more time making the tutorial then they did building the program… I do appreciate your efforts, more time and I’m sure I would have got it going but for such a (how do i say it nicely?) useless app (and I am just guessing,) I think two hours is about enough time to spend on trying to get it installed. I doubt I would even spend that much time using it. But, the thanks is genuine.

    might want to think about adding

    sudo apt-get –purge remove mrtg

    to the end of the tutorial

  169. Iceflatline

    i want a help on moving graph from old mrtg that had issues, to the this new installed mrtg. kindly assist me on the process to follow.

    best regards,

    Janvier R.

  170. Javier, I assume you mean you’d like to retain the historical data up to the time of the move? I’ve not done that before so I’m not sure. You might start with searching the system for the MRTG-related files and try simply moving them over to the new system. That said it might be easier to start fresh on the new system and forgo trying to keep the history.

  171. I have an issue listed already. using sudo indexmaker –output=/var/www/mrtg/index.html /etc/mrtg/mrtg.cfg tells me ERROR: did not find any matching data in cfg file.

    My mrtg.cfg file is in the /etc/mrtg/ directory as per your instructions.

    mrtg.cfg has root owner and 577 rights.
    Any ideas? Since I’m only creating a hmtl page, is there one I can simply copy and paste?

  172. Mike, sorry you are running into issues. It has been a very long time since I tried implementing MRTG in Ubuntu server, but assuming nothing has changed, that error suggests to me that the MRTG is not pulling data from the router. As to your question regarding HTML copy & paste, not that I am aware of, but it you could probably craft your own HTML page with a little effort. Good luck, and if I have some time I will test to see if I can reproduce the problem.

Leave a Reply

Your email address will not be published. Required fields are marked *

iceflatline