MRTG graphs without SNMP

From Nekochan
Revision as of 08:39, 7 January 2009 by Arabski (Talk | contribs) (Running with cron)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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


Installation

Install Mrtg_(neko_mips4).

Prerequisites

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

Configuration

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/load_avg.sh`
MaxBytes[load_avg]: 100
YLegend[load_avg]: LoadAvg * 100
Unscaled[load_avg]: ymwd
LegendI[load_avg]:
LegendO[load_avg]:
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/disk.sh`
kMG[disk_usage]: G
MaxBytes[disk_usage]: 35410400
YLegend[disk_usage]: Disk total/used
Unscaled[disk_usage]: ymwd
LegendI[disk_usage]:
LegendO[disk_usage]:
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/mem.sh`
kMG[memory_usage]: M
MaxBytes[memory_usage]: 256
AbsMax[memory_usage]: 256
YLegend[memory_usage]: Mem total/free
Unscaled[memory_usage]: ymwd
LegendI[memory_usage]:
LegendO[memory_usage]:
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/swp.sh`
kMG[swap_usage]: M
MaxBytes[swap_usage]: 1352
AbsMax[swap_usage]: 1352
YLegend[swap_usage]: Swap total/free
Unscaled[swap_usage]: ymwd
LegendI[swap_usage]:
LegendO[swap_usage]:
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/poll.sh`
MaxBytes[ec0]: 10000000000
YLegend[ec0]: Gigabytes
Unscaled[ec0]: ymwd
LegendI[ec0]:
LegendO[ec0]:
Suppress[ec0]: yd

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

Title[google_ping]: Ping to google.pl
PageTop[google_ping]: <H1>Ping to google.pl (RTT)</H1>
Options[google_ping]: nobanner,gauge,noinfo,nopercent
Target[google_ping]: `/usr/nekoware/etc/mrtg/google_ping.sh`
MaxBytes[google_ping]: 200
YLegend[google_ping]: RTT (ms)
Unscaled[google_ping]: ymwd
LegendI[google_ping]:
LegendO[google_ping]:
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

/usr/nekoware/etc/mrtg/load_avg.sh

Load Average multiplied by 100. Fetched from uptime.

#!/bin/sh
DATA=`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

/usr/nekoware/etc/mrtg/disk.sh

Disk usage. Fetched from df.

#!/bin/sh
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

/usr/nekoware/etc/mrtg/mem.sh

Memory usage. Fetched from top.

#!/bin/sh
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

/usr/nekoware/etc/mrtg/swp.sh

Swap usage. Fetched from top.

#!/bin/sh
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

/usr/nekoware/etc/mrtg/poll.sh

Total network traffic. Fetched from netstat.

#!/bin/sh
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

/usr/nekoware/etc/mrtg/uptime.pl

Machine uptime. Fetched from uptime.

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

/usr/nekoware/etc/mrtg/google_ping.sh

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

#!/bin/sh
PING="/usr/etc/ping"
ADDR="google.pl"
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
else
  echo $DATA | awk -F/ '{print $5 }' | cut -f1 -d" " | cut -f1 -d"."
fi
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

Links