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:

1

sudo apt-get install snmp snmpd

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:

1

sudo nano /etc/snmp/snmpd.conf

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:

1

agentAddress udp:161,udp6:161

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:

1

2

3

rocommunity public localhost

rocommunity COMMUNITY 192.168.0.0/16

rocommunity6 COMMUNITY 2003:de:2016:100::/56

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:

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

1

MaxBytes1[192.168.9.6-memory]: 448180

it must be

1

MaxBytes1[192.168.9.6-memory]: 458936320

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

1

2

3

Unscaled[localhost-cpu]: dwmy

Unscaled[localhost-memory]: dwmy

Unscaled[localhost.disk.xy]: dwmy

I like all interfaces with a graph type of mirror. That is, for all interfaces:

1

routers.cgi*GraphStyle[localhost_interface]: mirror

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:

Graphs

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

CPU

space used on /

Load average

Processes

Users

Traffic eth0

Memory available

Ping Times

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

1

2

3

4

5

6

sudo nano/etc/snmp/snmpd.conf

# EXTENDING THE AGENT

extend-shtemperature cat/sys/class/thermal/thermal_zone*/temp

sudo service snmpd restart

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