From 58fdfeebc823ede366163a5b75cbbf9c0e61aad3 Mon Sep 17 00:00:00 2001 From: Matt Amos Date: Mon, 23 Jan 2017 18:13:09 +0000 Subject: [PATCH] Add simple script to dump munin data from RRD to XML and tar it up somewhere downloadable. --- cookbooks/munin/files/default/rrddump.sh | 17 ++++++++++++++ cookbooks/munin/recipes/server.rb | 23 ++++++++++++++++++- .../munin/templates/default/rrddump.cron.erb | 3 +++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 cookbooks/munin/files/default/rrddump.sh create mode 100644 cookbooks/munin/templates/default/rrddump.cron.erb diff --git a/cookbooks/munin/files/default/rrddump.sh b/cookbooks/munin/files/default/rrddump.sh new file mode 100644 index 000000000..ba7e42f94 --- /dev/null +++ b/cookbooks/munin/files/default/rrddump.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +RRD_DIR=/var/lib/munin/openstreetmap +DIR=`mktemp -d` +NPROCS=8 + +function cleanup { +rm -rf "$DIR" +} + +trap cleanup EXIT + +cd "$RRD_DIR" +find -name "*.rrd" -print0 | xargs --null --max-procs=$NPROCS -I {} rrdtool dump {} "$DIR/{}.xml" + +cd "$DIR" +find -name "*.xml" -print0 | tar zcf - --null -T - diff --git a/cookbooks/munin/recipes/server.rb b/cookbooks/munin/recipes/server.rb index a03b7d684..d4f8cb047 100644 --- a/cookbooks/munin/recipes/server.rb +++ b/cookbooks/munin/recipes/server.rb @@ -81,7 +81,13 @@ remote_directory "/srv/munin.openstreetmap.org" do files_owner "root" files_group "root" files_mode 0o644 - purge true +end + +# directory to put dumped files in +directory "/srv/munin.openstreetmap.org/dumps" do + owner "www-data" + group "www-data" + mode 0o755 end apache_site "munin.openstreetmap.org" do @@ -95,6 +101,21 @@ template "/etc/cron.daily/munin-backup" do mode 0o755 end +# simple shell script to dump RRD data to a file +cookbook_file "/usr/local/bin/rrddump" do + source "rrddump.sh" + owner "root" + group "root" + mode 0o755 +end + +template "/etc/cron.d/rrddump" do + source "rrddump.cron.erb" + owner "root" + group "root" + mode 0o755 +end + munin_plugin "munin_stats" munin_plugin "munin_update" munin_plugin "munin_rrdcached" diff --git a/cookbooks/munin/templates/default/rrddump.cron.erb b/cookbooks/munin/templates/default/rrddump.cron.erb new file mode 100644 index 000000000..289fde65b --- /dev/null +++ b/cookbooks/munin/templates/default/rrddump.cron.erb @@ -0,0 +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"` -- 2.43.2