Created
March 22, 2011 21:43
-
-
Save andre/882143 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# killspike2 | |
# Remove (presumably erroneous) peaks from RRD files | |
# | |
# Matt Zimmerman <[email protected]>, 05/2002 | |
# | |
set -e | |
usage() { | |
>&2 echo "Usage: $0 <ds> <max> <rrd>..." | |
>&2 echo | |
>&2 echo "Remove all peaks above <max> from <ds> in the RRDs <rrd>..." | |
exit $1 | |
} | |
backupdir=backup.killspike2 | |
ds=$1 | |
max=$2 | |
if [ -z "$ds" -o -z "$max" ]; then | |
usage 1 | |
fi | |
shift 2 | |
rrds=$* | |
if [ "$ds" = "-h" -o -z "$rrds" ]; then | |
usage 1 | |
fi | |
mkdir $backupdir | |
echo "Making backups in $backupdir" | |
if type tempfile >/dev/null 2>&1; then | |
tempfile=`tempfile` | |
else | |
tempfile=killspike2.$$ | |
fi | |
for rrd in $rrds; do | |
echo $rrd | |
oldmax=`rrdtool info "$rrd" | awk '$1 == "ds['$ds'].max" { print $3 }'` | |
if [ -z "$oldmax" ]; then | |
>&2 echo "Could not determine current max for DS '$ds' in $rrd" | |
exit 1 | |
elif [ "$oldmax" = "NaN" ]; then | |
oldmax=U | |
fi | |
cp "$rrd" "$backupdir" | |
rrdtool tune "$rrd" --maximum "$ds:$max" | |
rrdtool dump "$rrd" > "$tempfile" | |
mv "$rrd" "old.$rrd" | |
rrdtool restore -r "$tempfile" "$rrd" | |
rrdtool tune "$rrd" --maximum "$ds:$oldmax" | |
done | |
rm -f "$tempfile" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment