]> git.openstreetmap.org Git - chef.git/commitdiff
Merge pull request #110 from zerebubuth/munin-dump-fixes
authorMatt Amos <zerebubuth@gmail.com>
Tue, 24 Jan 2017 13:18:05 +0000 (13:18 +0000)
committerGitHub <noreply@github.com>
Tue, 24 Jan 2017 13:18:05 +0000 (13:18 +0000)
Fixes to munin dump functionality

cookbooks/munin/files/default/rrddump.sh
cookbooks/munin/templates/default/rrddump.cron.erb

index ba7e42f94137330ea682e3b84318554095c45d62..08942038eeefd6e4e58e176eea80a049e15d2aa9 100644 (file)
@@ -2,16 +2,32 @@
 
 RRD_DIR=/var/lib/munin/openstreetmap
 DIR=`mktemp -d`
-NPROCS=8
+DUMP_DIR=/srv/munin.openstreetmap.org/dumps
+TARGET_TGZ=`date "+munin-data-%Y-%m-%d.tar.gz"`
+KEEP_OLD_COUNT=3
 
 function cleanup {
-rm -rf "$DIR"
+  rm -rf "$DIR"
 }
 
 trap cleanup EXIT
 
+set -e
+
 cd "$RRD_DIR"
-find -name "*.rrd" -print0 | xargs --null --max-procs=$NPROCS -I {} rrdtool dump {} "$DIR/{}.xml"
+for f in *.rrd; do
+  rrdtool dump "$f" "$DIR/${f}.xml"
+  touch -r "$f" "$DIR/${f}.xml"
+done
 
 cd "$DIR"
-find -name "*.xml" -print0 | tar zcf - --null -T -
+find -name "*.xml" -print0 | tar zcf "dump.tar.gz" --null -T -
+
+# if we got here, then the file was created okay so we're okay to delete any
+# old files.
+find "${DUMP_DIR}" -name "munin-data-*.tar.gz" -print0 | \
+    sort -z -r | \
+    tail -z -n "+${KEEP_OLD_COUNT}" | \
+    xargs --null rm -f
+
+mv dump.tar.gz "${DUMP_DIR}/${TARGET_TGZ}"
index 289fde65b409392587a78e00369c66caff5686c0..33087c3fd3375a5086171fab244cb42613770dc0 100644 (file)
@@ -1,3 +1,3 @@
 MAILTO=zerebubuth@gmail.com
-# do the dump in the early hours of the morning
-43 3 * * * www-data nice /usr/local/bin/rrddump > /srv/munin.openstreetmap.org/dumps/`date "+munin-data-%Y-%m-%d.tar.gz"`
+# do the dump & cleanup in the early hours of the morning
+43 3 * * * www-data nice /usr/local/bin/rrddump