Created
October 9, 2012 18:44
-
-
Save andre/3860636 to your computer and use it in GitHub Desktop.
remove troughs from rrd files (like killspike.sh, but for troughs
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 | |
# | |
# killtrough | |
# Remove (presumably erroneous) troughs from RRD files | |
# | |
# Matt Zimmerman <[email protected]>, 05/2002 | |
# | |
# Modified by Andre Lewis to kill troughs instead of peaks 10/2012 | |
set -e | |
usage() { | |
>&2 echo "Usage: $0 <ds> <min> <rrd>..." | |
>&2 echo | |
>&2 echo "Remove all troughs below <min> from <ds> in the RRDs <rrd>..." | |
exit $1 | |
} | |
backupdir=backup.killspike2 | |
ds=$1 | |
min=$2 | |
if [ -z "$ds" -o -z "$min" ]; 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 | |
oldmin=`rrdtool info "$rrd" | awk '$1 == "ds['$ds'].min" { print $3 }'` | |
if [ -z "$oldmin" ]; then | |
>&2 echo "Could not determine current min for DS '$ds' in $rrd" | |
exit 1 | |
elif [ "$oldmin" = "NaN" ]; then | |
oldmin=U | |
fi | |
cp "$rrd" "$backupdir" | |
rrdtool tune "$rrd" --minimum "$ds:$min" | |
rrdtool dump "$rrd" > "$tempfile" | |
mv "$rrd" "old.$rrd" | |
rrdtool restore -r "$tempfile" "$rrd" | |
rrdtool tune "$rrd" --minimum "$ds:$oldmin" | |
done | |
rm -f "$tempfile" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment