Monday, May 12, 2008

MRTG scripts (HDD space & swap)

Two shell scripts I often use on my MRTG setups, the first one 'mrtg-df.sh' returns the available and used space on a given partition, you have to pass the partition name as an option when executing it. To get this one to work on OpenBSD, you have to edit the line to be like this:

df=`df -k $part | tail -1`

Since 'df' on OpenBSD works with 512 values.


The other one 'mrtg-swap.sh' returns the amount of swap, and shows how much is actually being used by the system.
This one does not work on OpenBSD, you are better to setup SNMP to poll the data
I have found both of those scripts some four years ago on the internet.


#!/bin/sh
# mrtg-df.sh

PATH=/bin:/usr/bin

part=$1

# The external mrtg probe returns up to 4 lines of output:
# 1. Line: current state of the 'incoming bytes counter', actually, the available HDD space
# 2. Line: current state of the 'outgoing bytes counter', actually the used HDD space
# 3. Line: string, telling the uptime of the target.
# 4. Line: telling the name of the invoked partition.

df=`df $part | tail -1`

# we'll list the available blocks as "incoming" as that's the solid green bar

echo $df | awk '{print $4}' # available
echo $df | awk '{print $3}' # used
uptime | cut -d, -f 1 | awk '{print $3, $4}'
echo $df | awk '{print $1}'

# EoF #



#!/bin/sh
# mrtg-swap.sh
# This script monitors the swap usage.
totalswap=`/usr/bin/free |grep Swap |awk '{print $2}'`
usedswap=`/usr/bin/free |grep Swap |awk '{print $3}'`
echo "$totalswap"
echo "$usedswap"

# EoF #

Labels: , , ,

0 Comments:

Post a Comment

<< Home