Table of Contents

FreeBSD gmirror (geom based RAID-1) monitor

Author Brian Scott
Compatibility Xymon 4.3
Requirements FreeBSD, Bourne Shell (sh)
Download None
Last Update 2011-08-12

Description

Simple shell script to monitor FreeBSD geom based mirroring.

Status is red for degraded (missing a component) and yellow when recovering.

Installation

Pretty much standard fare:

[gmirror]
    ENVFILE /home/hobbit/server/etc/xymonserver.cfg
    NEEDS xymond
    CMD  $XYMONHOME/ext/gmirror.sh
    LOGFILE $XYMONSERVERLOGS/gmirror.log
    INTERVAL 5m

Or the equivalent on the client side.

Source

gmirror.sh

Show Code ⇲

Hide Code ⇱

#!/bin/sh

COLUMN=gmirror

HOSTNAME="`hostname`"
COLOUR=green

# % gmirror status
#       Name    Status  Components
#mirror/root  COMPLETE  ad8p2 (ACTIVE)
#						ad10p2 (ACTIVE)
# mirror/var  COMPLETE  ad8p4 (ACTIVE)
#						ad10p4 (ACTIVE)
# mirror/usr  COMPLETE  ad8p6 (ACTIVE)
#						ad10p6 (ACTIVE)
#mirror/home  COMPLETE  ad8p7 (ACTIVE)
#						ad10p7 (ACTIVE)

# STARTING, COMPLETE, DEGRADED -> yellow, green, red
/usr/bin/time -p gmirror status >$XYMONTMP/$COLUMN.out 2>&1
rc=$?
SECONDS=`egrep "^real" $XYMONTMP/${COLUMN}.out | awk '{printf $2}'`

if [ $rc -ne 0 ]; then
	COLOUR=red
	MSG="gmirror query failed

`cat $XYMONTMP/${COLUMN}.out|grep -v '^\(real\|user\|sys\)'`

Seconds: ${SECONDS}
"
else
	grep ' DEGRADED ' $XYMONTMP/$COLUMN.out >/dev/null
	if [ $? -eq 0 ]; then
		COLOUR=red
	else
		grep ' STARTING ' $XYMONTMP/$COLUMN.out >/dev/null
		if [ $? -eq 0 ]; then
			COLOUR=yellow
		fi
	fi
	MSG="gmirror query succeeded

`cat $XYMONTMP/${COLUMN}.out|grep -v '^\(real\|user\|sys\)'`

Seconds: ${SECONDS}
"
fi
$XYMON $XYMSRV "status $HOSTNAME.$COLUMN $COLOUR `date`

$MSG"
$RM $XYMONTMP/${COLUMN}.out

exit 0

Known Bugs and Issues

To Do

Nice features like green/red/yellow dots against individual mirrors.

Ability to exclude mirrors that we don't care about.

Credits

As with all of these things, the code started out by kicking around other people's code.

Changelog