Last active
June 23, 2020 10:25
-
-
Save glamrock/b30bd4239d94595178501209c1f31260 to your computer and use it in GitHub Desktop.
Ganglia rrd export / import
This file contains hidden or 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/bash -xe | |
# Note: run from /var/lib/ganglia directory, no need for subdir | |
# Run with: find /var/lib/ganglia/rrds/ -type d -exec sh -c 'cd "{}" ; /var/lib/ganglia/rrd_exporter.sh ;' \; | |
# backup current rrd files -- tar all and place in /tmp | |
tar --exclude='*.xml' -cvf /tmp/rrds-"$(date --date='now' +%F-%R)".tar rrds/* | |
echo "Backed up files in /tmp" | |
#Pull in rrd files one at a time | |
for i in *.rrd | |
do | |
# if .xml file already exists, read next file | |
if [ -f "$(basename "$i" .rrd).xml" ] | |
then | |
echo "$(basename "$i" .rrd).xml already exists. Moving on." | |
continue | |
fi | |
# export rrd file as xml, leaving in current directory | |
rrdtool dump "$i" > "$(basename "$i" .rrd).xml" | |
done | |
# tar all the .xml files, while preserving the directory structure | |
tar --exclude='*.rrd' -cvf /tmp/xml-rrds-"$(date --date='now' +%F-%R)".tar rrds/* | |
echo "DONE. Check /tmp for files." |
This file contains hidden or 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/bash -xe | |
# Note: run from /var/lib/ganglia directory, no need for subdir | |
# untar files in place before running. | |
# Run with: find /var/lib/ganglia/rrds/ -type d -exec sh -c 'cd "{}" ; /var/lib/ganglia/rrd_importer.sh ;' \; | |
# Stop processes | |
service ganglia-monitor stop | |
service gmond stop | |
service gmetad stop | |
# backup current rrd files -- tar all and place in /tmp | |
tar --exclude='*.xml' -cvf /tmp/rrds-"$(date --date='now' +%F-%R)".tar rrds/* | |
echo "Backed up files in /tmp" | |
#Pull in rrd files one at a time | |
for i in *.xml | |
do | |
# # if .rrd file already exists, assume its been imported and read next file | |
# if [ -f "$(basename "$i" .xml).rrd" ] | |
# then | |
# echo "$i already exists. Moving on." | |
# continue | |
# fi | |
# export rrd file as xml, leaving in current directory | |
rrdtool restore "$i" "$(basename "$i" .xml).rrd" -f # force overwrite existing rrds | |
done | |
# fix ganlia permissions | |
chown -R ganglia:ganglia rrds/* | |
echo "DONE. Restarting services." | |
service gmetad start | |
service ganglia-monitor start | |
# gmond is started by ganglia-monitor | |
echo "Services restarted. Check ganglia." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
importing RRDs with rrdtool will frequently bork the permissions, so be sure to set permissions to ganglia:ganglia after import.