Remote Gathering of non SNMP data through NRPE plugins for MRTG

by @jehiah on 2003-12-30 22:12UTC
Filed under: All , SysAdmin

While Multi Router Traffic Grapher (MRTG) is designed for graphing SNMP data over time, it also has the capability to graph data from other scripts. While it is easy to execute scripts localy and graph the data, it is difficult to do that remotely in a secure fashion. This implementation uses Nagios Remote Procedure Execution (NRPE) to acomplish the task. Nagios (screenshots here) is a network monitoring tool, which would be an ideal companion to MRTG.

## Overall Setup

  • NRPE installed on remote machine
  • Script on remote machine
  • nrpe.cfg file on remote host
  • MRTG installed on host
  • checknrpe plugin on host (NRPE not rquired to be installed)
  • MRTG configured to execute remote script through local checknrpe plugin.

1) Install NRPE on remote host (inet or xinetd) follow standard install instructions

2) Script on remote machine. Here are three scripts that check system load, Ethernet Traffic, Ram and Swap usage all without SNMP. They have been tested to work on Redhat 6.0,6.2,7.2,7.3. mrtgnrpeplugins.tar.gz. Extract them to the same directory as NRPE plugins (/usr/local/nagios/libexec for me)

You can modify any script to work through nrpe like this it must return data in the following format quot;data1|data2|uptime|hostname” all in a single string, delimintated by pipes.

3) nrpe.cfg file on remote host. add entries to the end of /etc/nrpe.cfg file on remote host with an entry for each script that you want to use.

command[mrtgeth0]=/usr/local/nagios/libexec/mrtgtrafficeth0.sh command[mrtgeth1]=/usr/local/nagios/libexec/mrtgtrafficeth1.sh command[mrtgload]=/usr/local/nagios/libexec/mrtgload.pl command[mrtgramswap]=/usr/local/nagios/libexec/mrtgramswap.sh

4) Install MRTG on host

5) setup nrpe on host You only need the checknrpe from the plugins directory

6) Configure MRTG on host add entry to crontab so that MRTG gets new stats every 5 min and rebuilds data

0-59/5 * * * * /usr/local/mrtg-2/bin/mrtg /etc/mrtg/mrtg.cfg

#sample /etc/mrtg.cfg file
WorkDir: /path/to/webserver/root/mrtg/
Refresh: 300
Interval: 5

#------remoteservername--------eth0 traffic---------------
Target[remoteservernameeth0]: /usr/local/nagios/libexec/check_nrpe -H emoteservername -c mrtg_eth0 | awk -F "|" '{print $1"n"$2"n"$3"n"$4}'
Title[remoteservernameeth0]: remoteservername Eth0 Traffic
MaxBytes[remoteservernameeth0]: 1000000
PageTop[remoteservernameeth0]: <h1>remoteservername Eth0 Traffic</h1>
Options[remoteservernameeth0]: growright
WithPeak[remoteservernameeth0]: wmy
Legend1[remoteservernameeth0]: Ethernet Traffic In
Legend2[remoteservernameeth0]: Ethernet Traffic Out
LegendI[remoteservernameeth0]: Traffic In
LegendO[remoteservernameeth0]: Traffic Out
#------remoteservername--------eth0 traffic---------------
#------remoteservername--------eth1 traffic---------------
Target[remoteservernameeth1]: /usr/local/nagios/libexec/check_nrpe -H emoteservername -c mrtg_eth1 | awk -F &quot;|&quot; '{print $1&quot;n&quot;$2&quot;n&quot;$3&quot;n&quot;$4}'
Title[remoteservernameeth1]: remoteservername Eth1 Traffic
MaxBytes[remoteservernameeth1]: 1000000
PageTop[remoteservernameeth1]: <h1>remoteservername Eth1 Traffic</h1>
Options[remoteservernameeth1]: growright
WithPeak[remoteservernameeth1]: wmy
Legend1[remoteservernameeth1]: Ethernet Traffic In
Legend2[remoteservernameeth1]: Ethernet Traffic Out
LegendI[remoteservernameeth1]: Traffic In
LegendO[remoteservernameeth1]: Traffic Out
#------remoteservername--------eth1 traffic---------------
#------remoteservername--------load---------------
Target[remoteservernameload]: /usr/local/nagios/libexec/check_nrpe -H remoteservername -c mrtg_load | awk -F &quot;|&quot; '{print $1&quot;n&quot;$2&quot;n&quot;$3&quot;n&quot;$4}'
title[remoteservernameload]: remoteservername CPU Load (5min avg)
MaxBytes[remoteservernameload]: 500
PageTop[remoteservernameload]: <h1>remoteservername CPU Load</h1>
Options[remoteservernameload]: growright,gauge,nopercent,integer
Legend1[remoteservernameload]: CPU Load (x100)
Legend2[remoteservernameload]:
LegendI[remoteservernameload]: 5min load
LegendO[remoteservernameload]: 1min load
ShortLegend[remoteservernameload]: load
#------remoteservername--------load---------------
#------remoteservername--------ramswap---------------
Target[remoteservernameramswap]: /usr/local/nagios/libexec/check_nrpe -H remoteservername -c mrtg_ram_swap | awk -F &quot;|&quot; '{print $1&quot;n&quot;$2&quot;n&quot;$3&quot;n&quot;$4}' 
Title[remoteservernameramswap]: remoteservername Ram and Swap usage 
MaxBytes[remoteservernameramswap]: 2000000000 
PageTop[remoteservernameramswap]: <h1>remoteservername Ram &amp; Swap Usage</h1> 
Options[remoteservernameramswap]: growright,gauge,nopercent 
Legend1[remoteservernameramswap]: Ram Usage, in bytes 
Legend2[remoteservernameramswap]: Swap Usage, in bytes 
LegendI[remoteservernameramswap]: Ram Usage 
LegendO[remoteservernameramswap]: Swap Usage 
ShortLegend[remoteservernameramswap]: B 
#------remoteserver--------ram_swap---------------

Nagios is a registered Trademark of Ethan Galstad.

Alexander Meyer writes to add that you could also avoid the nrpe stuff and execute the scripts directly via ssh (wich is quite useful if you want to use it over unsecured networks or on machines that don’t allow reading in /proc for normal users (so you could wrap it into sudo)) like this:

Target[remotemachine_load]: ssh -l someuser -i /path/to/some/private/key remotemachine sudo /path/to/mrtg_load.pl | awk -F &quot;|&quot; '{print $1&quot;\n&quot;$2&quot;\n&quot;$3&quot;\n&quot;$4}'
Subscribe via RSS ı Email
© 2023 - Jehiah Czebotar