Skip to content

Instantly share code, notes, and snippets.

Created March 23, 2012 02:43
Show Gist options
  • Star 38 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save arantius/2166343 to your computer and use it in GitHub Desktop.
Save arantius/2166343 to your computer and use it in GitHub Desktop.
A very simple script to merge multiple RRD files, since none of those available seem to work.
#!/usr/bin/env python
"""Simple script to merge multiple RRD files together.
Accepts any number of RRD file names as arguments. Produces an "rrdtool dump"
style file on stdout. The last RRD file should have a slot for every possible
record in the resulting merged RRD.
Run something like:
$ python filea.rrd fileb.rrd filec.rrd | \
rrdtool restore /dev/stdin merged.rrd
import re
import subprocess
import sys
def main():
rrd_data = {}
rrds = sys.argv[1:]
last_rrd = len(rrds) - 1
for i, rrdname in enumerate(rrds):
p = subprocess.Popen(
('rrdtool', 'dump', rrdname), stdout=subprocess.PIPE)
for j, line in enumerate(p.stdout):
m ='<cf>(.*)</cf>', line)
if m:
cf =
m ='<pdp_per_row>(.*)</pdp_per_row>', line)
if m:
pdp =
m =' / (\d+) --> (.*)', line)
if m:
k = cf + pdp
rrd_data.setdefault(k, {})
if ('NaN' not in or ( not in rrd_data[k]):
rrd_data[k][] = line
line = rrd_data[k][]
if i == last_rrd:
print line.rstrip()
if __name__ == '__main__':
Copy link

how to work this scipt ?

ex : old.rrd new.rrd merged.rrd

i use this not working .

ERROR: opening 'argo.rrd': No such file or directory

Copy link

Well, first, the files need to actually exist. The first through second-to-last should be the sources, possibly overlapping in time, to be combined. The last should be a larger set, going back far enough to contain all of the data for the earlier files. Probably by "rrdtool resize ... GROW" on the newest file.

Copy link

mcdarren commented Jul 4, 2012


Would you happen to still have a copy of the perl script ( you referred to at ?
I would like to have a look at this script, and possibly fix it, but I'm having difficulty finding a copy.

many thanks,

Copy link

Thanks a lot, works like a charm 😃

Copy link

fuhbar commented Sep 2, 2015

Thanks pal for your fantastic work, you saved my life today!

Copy link

4zap commented May 7, 2016

This script made my day! Awesome! :)

Copy link

fanto666 commented Dec 11, 2017

This tool does not properly work with RRDs generated by smokeping.
The reason is apparently that smokeping RRD's have "uptime" record that is NaN all the time.
to merge smokeping RRDs, we need to check if all columns are "NaN", not only one (since that test will always be true).

Copy link

Thx for the script :)
Used it to merge munin history (not beautiful at all):

Copy link

Worked great for combining nagiosgraph! PING*pl.rrd | rrdtool restore /dev/stdin pl.rrd

Copy link

Thank you for this @arantius, worked perfectly.

Copy link

thank you , it is working properly

Copy link

hi . i use this command as below
python old/pop_site_tavanir04_traffic_in_28871.rrd new/pop_site_tavanir04_traffic_in_28871.rrd | rrdtool restore /dev/stdin merged.rrd
but i got this error:
ERROR: mmaping file 'old/pop_site_tavanir04_traffic_in_28871.rrd': Invalid argument

Copy link

i want to merge rrd file because i have gap between out graph

Copy link

m3rlinux commented Jan 17, 2023

Hi! Using the tool as below:

./ var/pnp4nagios/perfdata/host1/CPU_load_load1.rrd CPU_load_load1.rrd | rrdtool restore /dev/stdin merged.rrd

I got this error:

 File "", line 45
    print line.rstrip()
SyntaxError: invalid syntax
/dev/stdin:1: parser error : Extra content at the end of the document

ERROR: error reading/parsing XML: Extra content at the end of the document

Copy link

In my case the problem was python3
As I haven't the permission to do a "PR" I forked this git.
The changes are available here:

Copy link

Indeed, this script is over 10 years old and was written for Python 2.

Copy link

Yes! But it works like a charm with little changes ;)

Copy link

Tipiani commented Jun 1, 2023

It works perfect! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment