Networking How to Install and Configure MRTG on Ubuntu Server

236 Comments

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

(20161025) – The software versions used in this post were updated — 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

    Tags: , , ,

    236 Responses to “How to Install and Configure MRTG on Ubuntu Server”

    1. Tim Says:

      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. iceflatline Says:

      Thanks for your kind words Tim, glad you enjoyed the post.

    3. Hamish Says:

      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.

    4. iceflatline Says:

      Hamish, you’re very welcome.

    5. ask123 Says:

      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

    6. iceflatline Says:

      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.

    7. pym93 Says:

      Big props on the great how-to! Very nice, worked like a charm.

    8. iceflatline Says:

      pym93, thanks! Glad you enjoyed it.

    9. hopeful Says:

      thank you iceflatline for sharing this guide..very useful very convenient very useful

    10. Darwis Suryantoro Says:

      Hi, i’m Indonesian. Many thanks for your great tutorial Bro!

    11. iceflatline Says:

      You’re very welcome! Thanks for the comment.

    12. Sontaya Says:

      Thank you for sharing this guide.

      #For openSUSE 11.2, SLES

      $ ln -s /etc/init.d/mrtg /etc/rc2.d/S99mrtg
      $ ln -s /etc/init.d/mrtg /etc/rc2.d/K99mrtg

      Change to:

      $ ln -s /etc/init.d/mrtg /etc/init.d/rc2.d/S99mrtg
      $ ln -s /etc/init.d/mrtg /etc/init.d/rc2.d/K99mrtg

      Regards,
      http://www.susethailand.com/suseforum/

    13. iceflatline Says:

      Thanks Sontaya!

    14. noobie Says:

      Hi,

      Thanks for the great post?
      Any plans for adding password protection to this :>

    15. iceflatline Says:

      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.

    16. Manuel Says:

      @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.

    17. sil nic Says:

      Great tutorial!
      Many thanks from Romania :)!

    18. iceflatline Says:

      sil nic, you’re welcome. How’s things in Romania?

    19. Roy Berry Says:

      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

    20. iceflatline Says:

      Roy, thanks for your kind comments!

    21. Ammar Says:

      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

    22. iceflatline Says:

      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

    23. Ammar Says:

      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

    24. iceflatline Says:

      Ammar, no problem.

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

    25. Ammar Says:

      iceflatline,

      I installed it on windows but the problem when I try to access it http://ipaddress/mrtg .. nothing appears to me.

      Regards

    26. iceflatline Says:

      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!

    27. Iqbal Says:

      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

    28. iceflatline Says:

      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.

    29. Jargalan Says:

      thats very coooool :)

      thanks a lot from Mongolia UB

    30. luckysanj Says:

      That’s great job…Thanks alot from luckysanj…very very nice hints & nice tutorial..

    31. supernoob Says:

      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?

    32. iceflatline Says:

      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.

    33. supernoob Says:

      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?

    34. supernoob Says:

      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.

    35. iceflatline Says:

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

    36. Thom Says:

      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?”

    37. vaibhav Says:

      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..

    38. iceflatline Says:

      I have not encountered this error before. I’ll see if I can duplicate it.

    39. iceflatline Says:

      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”).

    40. Leif Madsen Says:

      Worked great first try! The init.d script was especially helpful. Great job!

    41. iceflatline Says:

      My pleasure Leif, thanks for your comments.

    42. Niclas Says:

      Terrific! Epic guide.

    43. iceflatline Says:

      My pleasure Niclas, thanks for the kind words.

    44. Tharaka Says:

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

    45. iceflatline Says:

      Tharaka, excellent; glad it helped.

    46. cyberfido Says:

      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! :)

    47. iceflatline Says:

      Ciao cyberfido. You’re welcome, I’m glad the post was of help to you.

    48. katsumoto Says:

      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.

    49. iceflatline Says:

      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?

    50. katsumoto Says:

      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

    51. iceflatline Says:

      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.

    52. MrtgProblem Says:

      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 ????

    53. iceflatline Says:

      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]

    54. MrtgProblem Says:

      i dont have this files in /etc/mrtg only mrtg.cfg but still not working

    55. iceflatline Says:

      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?

    56. MrtgProblem Says:

      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

    57. iceflatline Says:

      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.

    58. MrtgProblem Says:

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

    59. luckysanj Says:

      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.

    60. iceflatline Says:

      luckysanj, having not done that before I’m unsure; however, you might try looking at the Interface by IP section of the MRTG configuration reference to see if that will meet your needs.

    61. ern@krypton Says:

      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.

    62. iceflatline Says:

      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.

    63. Has9 Says:

      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

    64. iceflatline Says:

      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.

    65. wale89 Says:

      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 =)

    66. iceflatline Says:

      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.

    67. Mikko Says:

      Greetings from Finland and thank you for great HOWTO. Helped me and a few friends a lot. :)

    68. Suhail Says:

      Thanks guys, for the simple how to guide!!

    69. iceflatline Says:

      Mikko, Suhail, thank you kindly for your comments.

    70. rashmani Says:

      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*

    71. iceflatline Says:

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

    72. bhargavi Says:

      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

    73. iceflatline Says:

      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.

    74. Andrew Says:

      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 )

    75. iceflatline Says:

      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.

    76. Andrew Says:

      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”.

    77. Andrew Says:

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

    78. Andrew Says:

      Success. Your script is fine, but need to be careful that it is copied correctly.

    79. iceflatline Says:

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

    80. david Says:

      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.

    81. Payam Says:

      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 ?

    82. Setting up MRTG on Ubuntu 10.04 LTS | The Internet made me do it! Says:

      […] MRTG on Ubuntu Server – Linux Basement How to Install and Configure MRTG on Ubuntu Linux Home Networking – HOWTO Monitor Server Performance The Tuxnetworks Linux Bible: […]

    83. tony Says:

      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.

    84. iceflatline Says:

      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

    85. SupermanInNY Says:

      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.

    86. iceflatline Says:

      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.”

    87. SupermanInNY Says:

      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.

    88. iceflatline Says:

      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.

    89. SupermanInNY Says:

      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.

    90. iceflatline Says:

      SupermanInNY, Great! Glad you were able to sort it out.

    91. Henz Says:

      An amazing tutorial. Thank you.

    92. iceflatline Says:

      Henz, thank you.

    93. seswho Says:

      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.

    94. iceflatline Says:

      seswho, thanks for your comment. I hope you got to eat ;-)

    95. Pocopico Says:

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

    96. iceflatline Says:

      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.

    97. Daniel Says:

      This worked as advertised for me. Great writeup.

    98. iceflatline Says:

      Daniel, thank for giving it a go and for taking the time to comment. Glad it worked for you.

    99. tony Says:

      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

    100. iceflatline Says:

      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?

    101. tony Says:

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

    102. iceflatline Says:

      tony, in that case you may want to look at the MRTG Configuration Reference. In particular the MaxBytes and AbsMax keywords. There may be others.

    103. Yannis Says:

      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

    104. iceflatline Says:

      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?

    105. Yannis Says:

      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.

    106. Nagios and MRTG Says:

      […] work ok … next task is MRTG with Nagios and i have installed MRTG on the same machine following this article.Its work ok .. there is a graph on http://localhost/mrtg. And i have found that my path for […]

    107. tony5at Says:

      How about snmp v3??? is there anything with MRTG to collect V3? thanks and merry christmas!

    108. iceflatline Says:

      tony5at, thanks! A very merry xmas to you as well.

      Yes, MRTG does support SNMP v3. Use the –enablesnmpv3 {yes|no} option in cfgmaker. See http://oss.oetiker.ch/mrtg/doc/cfgmaker.en.html

    109. parvez Says:

      hi, i need help please
      i can not run the script

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

      please help

    110. iceflatline Says:

      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?

    111. Verb Says:

      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?

    112. iceflatline Says:

      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.

    113. Verb Says:

      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.

    114. Verb Says:

      Ice….I got it all sorted. Somehow I started install on my desktop machine and not my server. DOAH! But I found some good snmp installation instructions at Andrew Pakpahan’s block and I”m all set. Here’s the link in case anyone else is having issues with snmp installation. http://andrewpakpahan.blogspot.com/2012/09/how-to-enable-snmp-monitoring-on-ubuntu.html

      Thanks again for this great write up! Awesome!

    115. iceflatline Says:

      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.

    116. Odee Says:

      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? :)

    117. iceflatline Says:

      Odee, I’m confused. Are you saying MRTG won’t start?

    118. Jan Says:

      Thank you for this perfect walk-trough!

    119. iceflatline Says:

      Jan, thanks! Appreciate the comment.

    120. Tomek Says:

      Great Job!!! One of the best guides i’ve ever seen.

    121. iceflatline Says:

      Thanks!

    122. Jim Says:

      Great job on this! Thanks for taking the time to share.

    123. iceflatline Says:

      Jim, my pleasure. Thanks for the kind words.

    124. Bizax Says:

      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.

    125. iceflatline Says:

      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.

    126. Liviu Says:

      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.

    127. iceflatline Says:

      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.

    128. Charz Says:

      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

    129. iceflatline Says:

      Charz, sorry, I’m not really sure.

    130. Charz Says:

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

      Thanks.

    131. Luke Says:

      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

    132. iceflatline Says:

      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?

    133. Lihazna Says:

      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?

    134. Lihazna Says:

      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?

    135. iceflatline Says:

      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.

    136. sacredrose Says:

      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.

    137. iceflatline Says:

      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.

    138. sacredrose Says:

      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

    139. iceflatline Says:

      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 .

    140. sacredrose Says:

      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

    141. iceflatline Says:

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

    142. McParty Says:

      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

    143. iceflatline Says:

      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.

    144. jeanpierre Says:

      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?

    145. iceflatline Says:

      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]

    146. jeanpierre Says:

      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.

    147. iceflatline Says:

      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?

    148. kashif Says:

      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.

    149. iceflatline Says:

      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.

    150. DreadLuck22 Says:

      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

    151. Ubuntu Noob Says:

      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

    152. vvsvinu Says:

      thanks fro such a nice tutorial

    153. Ubuntu Noob Says:

      Thanks I was able to see multiple routers….

    154. bhesterberg Says:

      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?

    155. iceflatline Says:

      bhesterberg,

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

    156. bhesterberg Says:

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

    157. bhesterberg Says:

      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”

    158. iceflatline Says:

      bhesterberg, is the apache web server running?

    159. bhesterberg Says:

      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 :-)

    160. iceflatline Says:

      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.

    161. iceflatline Says:

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

    162. bhesterberg Says:

      Yea I see and understand that now. Its working now, great post for those that can follow directions :-)

    163. bhesterberg Says:

      Ok I’m wrong, it’s not working. When I browse to the http://192.168.5.234/mrtg I get a
      The requested URL /mrtg was not found on this server.

      Apache/2.4.7 (Ubuntu) Server at 192.168.5.234 Port 80

    164. iceflatline Says:

      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.

    165. iceflatline Says:

      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]

    166. bhesterberg Says:

      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!!

    167. iceflatline Says:

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

    168. iceflatline Says:

      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.

    169. ray-damji Says:

      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.

    170. iceflatline Says:

      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.

    171. ray-damji Says:

      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.#

    172. iceflatline Says:

      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.

    173. ray-damji Says:

      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

    174. iceflatline Says:

      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…

    175. Simba Says:

      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.

    176. iceflatline Says:

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

    177. Simba Says:

      @ 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.

    178. Gugun Samudera Says:

      graph does not appear, why ??

    179. iceflatline Says:

      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?

    180. Nagios 4 and MRTG Install Directions | Pilgrim's Journey Says:

      […] iceflatline […]

    181. Adrian Says:

      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

    182. iceflatline Says:

      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.

    183. bobby Says:

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

    184. iceflatline Says:

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

    185. bobby Says:

      I am using 14.04.2 LTS

    186. iceflatline Says:

      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.

    187. Ryan Says:

      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

    188. iceflatline Says:

      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 :)

    189. Ryan Says:

      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!

    190. iceflatline Says:

      Ryan, excellent. Glad you got it fired up.

    191. Rick Says:

      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.

    192. iceflatline Says:

      Rick, thanks for the kind words. Glad it worked for you.

    193. Martino Says:

      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

    194. iceflatline Says:

      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.

    195. Rick Says:

      Would you happen to know how to incorporate MRTG Ping-Probe with MRTG?

    196. iceflatline Says:

      Rick, apologies, I do not.

    197. Charz Says:

      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

    198. iceflatline Says:

      Charz, I don’t think it can be done with MRTG. You might take a look at RRDtool

    199. Chris Looi Says:

      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.

    200. iceflatline Says:

      Chris, thanks for the kind words! Glad it worked well for you.

    201. Adrian Says:

      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.

    202. iceflatline Says:

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

    203. Adrian Says:

      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…

    204. iceflatline Says:

      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

    205. Adrian Says:

      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!

    206. Charz Says:

      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!

    207. iceflatline Says:

      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.

    208. kumaran Says:

      This is working,
      Thanks for the everything…

    209. fredv Says:

      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

    210. iceflatline Says:

      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.

    211. Fabiana Martins Says:

      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.

    212. iceflatline Says:

      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.

    213. Fiqah Says:

      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

    214. iceflatline Says:

      Fiqah, I’m not sure whether or not MRTG supports something like that. You can check through the documentation at http://oss.oetiker.ch/mrtg/doc/index.en.html

    215. Dambar Says:

      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

    216. iceflatline Says:

      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.

    217. Bilal Says:

      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 ???

    218. iceflatline Says:

      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.

    219. Bilal Says:

      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

    220. iceflatline Says:

      Bilal, +1 :)

    221. Jason Chase Says:

      Even after 6 years, this is still a great howto. NIce work and thanks!

      Jason

    222. iceflatline Says:

      Jason, thanks for the kind words. You’re very welcome.

    223. Hari Krishna Says:

      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?

    224. iceflatline Says:

      Hari, not that I’m aware of. Perhaps you could set something up with cron?

    225. Hari Krishna Says:

      Ice,

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

      sudo service mrtg start
      mrtg: unrecognized service

    226. iceflatline Says:

      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.

    227. Rob Says:

      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?

    228. iceflatline Says:

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

    229. Shane Says:

      Thanks for the great tutorial.

    230. iceflatline Says:

      Thanks for the kinds words Shane.

    231. Edwin Says:

      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?

    232. iceflatline Says:

      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)?

    233. EnriqueSepúlveda Says:

      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.

    234. iceflatline Says:

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

    235. dabl Says:

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

    236. iceflatline Says:

      dabl, awesome! Thanks for commenting.

    Leave a Reply