Exporting And Importing Munin Graph Data

Sunday, July 21, 2013 - 20:38

When Munin does a data update it stores all of the data from the nodes as a set of rrd files. These files are then picked up by the munin-graph and munin-html programs and turned into the graph images and web pages that you are probably familiar with if you use Munin.

The default location for Munin to store these data files is within the directory /var/lib/munin. Each group you define in your config is given it's own sub directory and the rrd data files for all servers within each group are kept within that directory. If you kept the default Munin config file you will probably have a directory called localhost which will contain all of the rrd files for your Munin server.

If you want to create a backup solution for Munin then you only need to backup these directories, and perhaps the munin.conf file in /var/lib/munin. If you have any problems then you can just restore these directories back to where they were and Munin will pick up the data automatically when it runs the next update. You don't need to keep hold of the HTML pages as these are completely rewritten when an update is run.

This is fine when restoring the data files back to the same machine, but you might find you have problems if you try to move these data files from one server to another. When I did this Munin generated the following error in it's munin-update.log file.

Munin: This RRD was created on another architecture

The problem was that I had moved these files from a 32 bit system to a 64 bit system and this means that the file was unreadable by the new machine due to the different architecture. The rrd files used by Munin are in a binary format, and it is not possible to simply alter them using an editor. The solution here is to use a tool called rrdtool to convert the rrd files into XML files on the old server and then import them on the new server. The rrdtool tool is used to interact with rrd files in certain ways and in this case we use the dump flag to convert the binary files into a the more readable format of XML.

The following command is used to convert all of the rrd files within the localdomain folder into the new xml format. For completeness I also include the creation of the destination directories.

cd /var/lib/munin/localdomain
mkdir ~/munin/localdomain
for i in ./*.rrd;do rrdtool dump $i ~/munin/localdomain/$i.xml;done

You will need to do the same thing for each of the groups you have in your Munin setup.

Once you can converted these files you can back them up or even just move then to the destination server. The following command will take a directory of XML files (as created by rrdtool) and convert them into binary rrd files. This time we are using the restore rrdtool flag. Again, for completeness I have included some commands to delete the current Munin rrd directory (otherwise the tool will error), and to set the correct permissions on the directory afterwards.

rm -rf /var/lib/munin/localdomain
mkdir /var/lib/munin/localdomain
cd /home/kubuntu/munin/localdomain
for i in ./*.xml; do rrdtool restore "$i" "/var/lib/munin/localdomain/${i%.xml}"; done
chmod -R 766 /var/lib/munin
chown -R munin:munin /var/lib/munin

With these two scripts you should be able to backup any data you have in your Munin install, or migrate your install to any architecture.

philipnorton42's picture

Philip Norton

Phil is the founder and administrator of #! code and is an IT professional working in the North West of the UK.
Google+ | Twitter


hi, help me plz, why when i run this commands in the correct rrd's directories
#for i in ./*.rrd;do rrdtool dump $i ~/munin/localdomain/$i.xml;done

obtain this error:

ERROR: usage rrdtool dump [--header|-h {none,xsd,dtd}] [--no-header]file.rrd [file.xml]
ERROR: usage rrdtool dump [--header|-h {none,xsd,dtd}] [--no-header]file.rrd [file.xml]
ERROR: usage rrdtool dump [--header|-h {none,xsd,dtd}] [--no-header]file.rrd [file.xml]
ERROR: usage rrdtool dump [--header|-h {none,xsd,dtd}] [--no-header]file.rrd [file.xml]
ERROR: usage rrdtool dump [--header|-h {none,xsd,dtd}] [--no-header]file.rrd [file.xml]
ERROR: usage rrdtool dump [--header|-h {none,xsd,dtd}] [--no-header]file.rrd [file.xml]

my rrds files have this names format:

if_mcastpkts-1000Gbic850Sx Port 1_10 Name acc-cen-2-a1.rrd
if_mcastpkts-1000Gbic850Sx Port 1_11 Name acc-cen-2-b1.rrd
if_mcastpkts-1000Gbic850Sx Port 1_12 Name acc-cen-2-c1.rrd
if_mcastpkts-1000Gbic850Sx Port 1_13 Name acc-cen-3-a1.rrd
if_mcastpkts-1000Gbic850Sx Port 1_18 Name acc-cen-4-c1.rrd

why error?

Add new comment