MRTG graphs without SNMP

From Higher Intellect Wiki
Jump to: navigation, search

MRTG allows you to plot graphs of various data gathered from a running system.


Install Mrtg_(neko_mips4).


You will also need a running webserver, to view pages that MRTG generates from another machine.


Create directory /usr/nekoware/etc/mrtg and put config file mrtg.conf there. This directory will also hold scripts we'll use for data gathering. Additionally you will need to create working directory under webserver's DocumentRoot - in this example it is /usr/nekoware/apache2/htdocs/_mrtg.

EnableIPv6: no
WorkDir: /usr/nekoware/apache2/htdocs/_mrtg

Interval: 5

Title[load_avg]: Load average * 100
PageTop[load_avg]: <H1>Load average * 100</H1>
Options[load_avg]: nobanner,gauge,noinfo,nopercent
Target[load_avg]: `/usr/nekoware/etc/mrtg/`
MaxBytes[load_avg]: 100
YLegend[load_avg]: LoadAvg * 100
Unscaled[load_avg]: ymwd
Suppress[load_avg]: y

Title[disk_usage]: Disk usage (GB)
PageTop[disk_usage]: <H1>Disk usage (GB)</H1>
Options[disk_usage]: nobanner,gauge,noinfo,nopercent
Target[disk_usage]: `/usr/nekoware/etc/mrtg/`
kMG[disk_usage]: G
MaxBytes[disk_usage]: 35410400
YLegend[disk_usage]: Disk total/used
Unscaled[disk_usage]: ymwd
Suppress[disk_usage]: y

Title[memory_usage]: Memory usage (MB)
PageTop[memory_usage]: <H1>Memory usage (MB)</H1>
Options[memory_usage]: nobanner,gauge,noinfo,nopercent
Target[memory_usage]: `/usr/nekoware/etc/mrtg/`
kMG[memory_usage]: M
MaxBytes[memory_usage]: 256
AbsMax[memory_usage]: 256
YLegend[memory_usage]: Mem total/free
Unscaled[memory_usage]: ymwd
Suppress[memory_usage]: y

Title[swap_usage]: Swap usage (MB)
PageTop[swap_usage]: <H1>Swap usage (MB)</H1>
Options[swap_usage]: nobanner,gauge,noinfo,nopercent
Target[swap_usage]: `/usr/nekoware/etc/mrtg/`
kMG[swap_usage]: M
MaxBytes[swap_usage]: 1352
AbsMax[swap_usage]: 1352
YLegend[swap_usage]: Swap total/free
Unscaled[swap_usage]: ymwd
Suppress[swap_usage]: y

Title[ec0]: Total network traffic (ec0)
PageTop[ec0]: <H1>Total network traffic (ec0)</H1>
Options[ec0]: nobanner,gauge,noinfo
Target[ec0]: `/usr/nekoware/etc/mrtg/`
MaxBytes[ec0]: 10000000000
YLegend[ec0]: Gigabytes
Unscaled[ec0]: ymwd
Suppress[ec0]: yd

Title[localuptime]: Uptime
PageTop[localuptime]: <H1>Uptime</H1>
Options[localuptime]: nobanner,gauge,noinfo,nopercent
Target[localuptime]: `/usr/nekoware/etc/mrtg/`
MaxBytes[localuptime]: 80
YLegend[localuptime]: Days
Unscaled[localuptime]: ymwd
Suppress[localuptime]: yd

Title[google_ping]: Ping to
PageTop[google_ping]: <H1>Ping to (RTT)</H1>
Options[google_ping]: nobanner,gauge,noinfo,nopercent
Target[google_ping]: `/usr/nekoware/etc/mrtg/`
MaxBytes[google_ping]: 200
YLegend[google_ping]: RTT (ms)
Unscaled[google_ping]: ymwd
Suppress[google_ping]: y

For explanation of options used, I recommend reading MRTG's online manual.

Data gathering methods

By default, MRTG uses SNMP for data gathering. Since SNMP (server side) is not very well supported on IRIX, we'll use an alternate method. Apart from SNMP, MRTG can be fed with data from external scripts. Output should be as follows:

1st value - incoming bytes
2nd value - outcoming bytes
3rd value - uptime of a target
4th value - name of a target

Scripts used


Load Average multiplied by 100. Fetched from uptime.

FIRST=`echo $DATA | cut -f4 -d":" | cut -f1 -d","`
SECOND=`echo $DATA | cut -f4 -d":" | cut -f2 -d","`
VAL1=`echo "$FIRST*100" | bc | cut -f1 -d"."`
VAL2=`echo "$SECOND*100" | bc | cut -f1 -d"."`
echo $VAL1
echo $VAL2
echo 0
echo 0


Disk usage. Fetched from df.

DATA=`df -k /dev/root | tail -1`
VAL1=`echo $DATA | cut -f3 -d" "`
VAL2=`echo $DATA | cut -f4 -d" "`
echo $VAL1
echo $VAL2
echo 0
echo 0


Memory usage. Fetched from top.

DATA=`top -b | grep Memory`
TOTAL=`echo $DATA | cut -f2 -d" " | cut -f1 -d"M"`
FREE=`echo $DATA | cut -f6 -d" " | cut -f1 -d"M"`
echo $TOTAL
echo $FREE
echo 0
echo 0


Swap usage. Fetched from top.

DATA=`top -b | grep Memory`
TOTAL=`echo $DATA | cut -f8 -d" " | cut -f1 -d"M"`
FREE=`echo $DATA | cut -f10 -d" " | cut -f1 -d"M"`
echo $TOTAL
echo $FREE
echo 0
echo 0


Total network traffic. Fetched from netstat.

netstat -p tcp | grep bytes | grep received | cut -f2 -d"(" | cut -f1 -d" "
netstat -p tcp | grep bytes | head -1 | cut -f2 -d"(" | cut -f1 -d" "
echo 0
echo 0


Machine uptime. Fetched from uptime.

$uptime = `uptime`;
$uptime =~ /up (.*?) day/;
$up = int($1);
print "$up\n";
print "$up\n";
print "0\n";
print "0\n";


ICMP Echo Round Trip Time to some site. in this example.

DATA=`$PING -c 10 $ADDR | grep -v 64`
LOSS=`echo $DATA | awk '{print $16 }' | tr -d % | cut -f1 -d"."`
echo $LOSS
if test "$LOSS" = "100" ; then
  echo 0
  echo $DATA | awk -F/ '{print $5 }' | cut -f1 -d" " | cut -f1 -d"."
echo 0
echo 0

Running with cron

We'll run the program at 5 minute interval, suppressing all output. Otherwise root would be flooded with cron mail.

0,5,10,15,20,25,30,35,40,45,50,55 * * * * /usr/nekoware/bin/mrtg --logging=/var/adm/mrtg.log /usr/nekoware/etc/mrtg/mrtg.conf > /dev/null 2>&1


Share your opinion