MRTG/Routers2: Adding a Linux Host

This post describes how to add a Linux machine to the MRTG/Routers2 monitoring server. First, the host must be able to process SNMP requests. Then, a *.cfg file for MRTG/Routers2 is created by running the “cfgmaker” tool with a host-template. Since a few values are wrong in the cfgmaker file, I also explain how to correct them. Finally, I am adding the mrtg-ping-probe lines to the configuration.

Installation of SNMP

Two packages are mandatory for SNMP: snmp which is the tool to send SNMP requests to a machine, and snmpd which is the daemon to listen on port 161 for incoming SNMP requests. On a Ubuntu machine, both packets can easily be installed with:

After that, the snmpd configuration must be customized in order to allow incoming SNMP requests. This slightly depends on whether these requests are sent from the localhost (e.g., if the MRTG machine wants to query itself), or from a remote host over the network (which is the normal case). In both cases, the snmpd.conf file must be opened with:

In the snmpd.conf, a paragraph called “AGENT BEHAVIOUR” specifies the listening state of snmpd. In order to allow incoming requests from any machine via IPv6 and legacy IP, the following line fits:

In the paragraph called “ACCESS CONTROL” a line that allows an SNMP COMMUNITY for read-only access can be specified like this examples, depending on IPv6 or nor:

Now restart the daemon with sudo service snmpd restart and test the configuration with the snmpwalk tool which runs through all (!) SNMP values the localhost presents: snmpwalk -v 2c -c public localhost .1.3.6. IPv6 pendant: snmpwalk -v 2c -c THISISTHEKEY udp6:host.domain.tld .1.3.6 . If there are many hundreds lines flowing over the screen, everything is ok.

Creating the CFG File

I am creating my *.cfg files for Linux servers with the host-generic.htp from Steve Shipways forum here. The main command is the following:

Again, for IPv6 you must use the following command:

This creates the “jw-vm01.cfg” file and customizes the settings. This file must then be copied into the “/etc/mrtg/” folder. MRTG will then query it. However, I advise to change the following lines:

  • Delete all lines under the “### Global Config Options” because they are not needed. Especially the “WorkDir:” value is wrong at this position since it is already specified in the global mrtg.cfg configuration file if it is installed due to my tutorial.
  • The memory values are wrongly calculated with the host template: They need to be multiplied with 1024. E.g., instead of
    it must be
  • The CPU, memory, and the filesystem graphs are not shown from “0 – 100 %” but only from “0 – current max value %”. In my opinion I get more information if the graph always shows up to 100 %. So I added the following lines to the appropriate sections of the CPU, memory, and all disks (replace “xy” by the disk value shown in the other lines):
  • I like all interfaces with a graph type of mirror. That is, for all interfaces:
  • Furthermore, I am always adding a ping to the node (which is not much interesting at the localhost in this example here, though). This requires to have the “mrtg-ping-probe” packaged installed. I listed the MRTG/Routers2 config here.
  • Finally, I have a recurrent coloring style, i.e., yellow for CPU, pink for processes, turquoise for users, and orange for RAM. So I added the following lines inside the appropriate sections:
     

Here is an example of my localhost *.cfg file with all the above mentioned changes:

 

Graphs

If everything is ok and MRTG stores the values correctly, the graphs should grow every five minutes and look like that:

 

[UPDATE] Raspberry Pi Temperature

When querying a Raspberry Pi you can also monitor the CPU temperature. This is the procedure: Extend the SNMP service on the Pi to hand out the temperature:

Walking the SNMP tree I found for example the following OID: 1.3.6.1.4.1.8072.1.3.2.3.1.1.11.116.101.109.112.101.114.97.116.117.114.101  or this one: 1.3.6.1.4.1.8072.1.3.2.4.1.2.5.116.101.115.116.51.1 . (I don’t know why they are different, but I don’t care.)

Add the MRTG target such as:

Note the HRule which inserts a line at 55 degree. Normally, a Pi should not exceed this temperature.

One thought on “MRTG/Routers2: Adding a Linux Host

  1. how to add new device in mrtg
    The configuration I did worked fine but now I know how to add the ip of the new router and how to put the title name in it like I had to add 192.168.1.5
    centos 7

    #com2sec notConfigUser default public
    com2sec local localhost public
    com2sec mynetwork 192.168.42.0/24 public
    group MyRWGroup v2c local
    group MyROGroup v2c mynetwork
    view all included .1 80

    mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf_original

    cd /etc/snmp/
    snmpwalk -v2c -c public localhost system
    cfgmaker –snmp-options=:::::2 –ifref=descr –ifdesc=descr –global ‘WorkDir: /var/www/html/mymrtg’ public@192.168.42.166 > /etc/mrtg/mrtg.cfg

    cd /var/www/html/
    mkdir mymrtg
    indexmaker –columns=1 /etc/mrtg/mrtg.cfg > /var/www/html/mymrtg/index.html

    vi /etc/cron.d/mrtg
    */5 * * * * root LANG=C LC_ALL=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg –lock-file /var/lock/mrtg/mrtg_l –confcache-file /var/lib/mrtg/mrtg.ok
    vi /etc/httpd/conf.d/mrtg.conf
    Alias /mrtg /var/www/html/mymrtg

    Require local
    # Require ip 10.1.2.3
    allowoverride all
    # Require host example.org

    192.168.42.166/mymrtg/

Leave a Reply

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