Script for detecting RRDs not collecting
Ed Ravin <[email protected]>
| Newsgroups | gmane.network.cricket.user |
|---|---|
| Message-ID | <[email protected]> |
> On Tue, Apr 24, 2007 at 05:26:34PM -0300, Nicolas Royo wrote: > > Im using cricket for monitoring customized wireless APs and > therefore, clientes that are very dinamic. > > As the number of targets rises to about 4000 clients, I was looking a > way for detecting who have activity and who dont. See attached script. It checks the log files and the RRD files for things that are out of date. I'm not sure if I would call it production quality, but it might fit the bill for you. If you're keeping things in your RRD directory that are old, like a router or host that's not online anymore but you kept the RRD in your config so you could compare against current graphs, then use the "--ignore" option for those files. ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ cricket-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/cricket-users
cricket.monitor
(text/plain, 2.7 KB)
#!/bin/sh
set -u
# Monitor a Cricket installation
# complain if it appears that Cricket is not running or if a
# configured Cricket directory is not getting any RRD updates
USAGE="Usage: cricket.monitor [-ignore dir-pattern ]"
# tasks:
# if cron job writes to temp file, make sure it is recent
# if log files are written to cricket-logs/NNN.0, make sure they
# are recent
# check RRD tree, complain if any directory containing .rrd files has
# no files within that have been updated recently. we don't want to
# complain if some .rrd files are going stale, since that could be
# just a removed or renamed interface or the like.
GFIND=/usr/local/bin/gfind
MINUTES=30 # how long before a file is considered "stale"
CRICKET_TOP=/rrd
# comment these out if you don't want to check them
CRICKET_LOGS=$CRICKET_TOP/cricket-logs
CRICKET_DATA=$CRICKET_TOP/cricket-data
debug=false
if [ ${DEBUG:-no} = YES ]
then
set -x
debug=true
fi
ignore=""
while [ "${1:-}" ]
do
case ${1:-} in
-ignore|--ignore) ignore="$ignore ${2:?$USAGE}"; shift ; shift ;;
-*) echo "$USAGE"; exit 23 ;;
*) break;;
esac
done
# it would be nice if vanilla sh supported arrays.
failure1=""
failure2=""
# complain if there are no files in dir with specified extension that have
# been updated in less than the specified minutes
staledircheck() { # dirname extension minutes
dirname=${1:?}
extension=${2:?}
minutes=${3:?}
allfilecount=$($GFIND 2>/dev/null $dirname -type f -name "*${extension}" | wc -l)
stalefilecount=$($GFIND 2>/dev/null $dirname -type f -name "*${extension}" -mmin +$minutes | wc -l)
if [ $stalefilecount -eq $allfilecount -a $allfilecount -ne 0 ]
then
return 0 # true, it's stale
else
return 1 # false, it's not stale
fi
}
if [ "${CRICKET_LOGS:-}" ]
then
for dir in $($GFIND 2>/dev/null $CRICKET_LOGS -type d -print)
do
if staledircheck $dir .0 $MINUTES
then
failure1="$failure1 $dir"
fi
done
fi
if [ "${CRICKET_DATA:-}" ]
then
for dir in $($GFIND 2>/dev/null $CRICKET_DATA -type d -print)
do
ignoredir=false
for pattern in $ignore
do
if echo $dir | egrep -q $pattern
then ignoredir=true
fi
done
if $ignoredir
then :
elif staledircheck $dir .rrd $MINUTES
then
failure2="$failure2 $dir"
fi
done
fi
if [ "$failure1$failure2" ]
then
failurehost=localhost
if [ "$failure2" ]
then
failuredirs=$(for dir in $failure2 ; do echo $dir; done | cut -d/ -f5 | sort -u)
if [ "$failuredirs" ]
then
failurehost="$failuredirs"
fi
fi
echo $failurehost
echo
if [ "$failure1" ]; then echo "All logfiles are stale in log dir: $failure1"; fi
if [ "$failure2" ]; then echo "All .rrd files are stale in these Cricket data directory(s): $failure2"; fi
return 1
else
return 0
fi