Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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 simple-merge-rrd.py 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 = re.search(r'<cf>(.*)</cf>', line)
if m:
cf = m.group(1)
m = re.search(r'<pdp_per_row>(.*)</pdp_per_row>', line)
if m:
pdp = m.group(1)
m = re.search(r' / (\d+) --> (.*)', line)
if m:
k = cf + pdp
rrd_data.setdefault(k, {})
if ('NaN' not in m.group(2)) or (
m.group(1) not in rrd_data[k]):
rrd_data[k][m.group(1)] = line
line = rrd_data[k][m.group(1)]
if i == last_rrd:
print line.rstrip()
if __name__ == '__main__':
main()
@okki-linux

This comment has been minimized.

Copy link

commented May 12, 2012

how to work this scipt ?

Usage:simple-rrd-merge.py

ex : simple-rrd-merge.py old.rrd new.rrd merged.rrd

i use this not working .

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

@arantius

This comment has been minimized.

Copy link
Owner Author

commented May 13, 2012

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.

@mcdarren

This comment has been minimized.

Copy link

commented Jul 4, 2012

Hi,

Would you happen to still have a copy of the perl script (rrd_merger.pl) you referred to at http://stackoverflow.com/questions/9816139/merge-multiple-rrds-over-time ?
I would like to have a look at this script, and possibly fix it, but I'm having difficulty finding a copy.

many thanks,
Darren

@Sieberkev

This comment has been minimized.

Copy link

commented Jan 29, 2015

Thanks a lot, works like a charm 😃

@fuhbar

This comment has been minimized.

Copy link

commented Sep 2, 2015

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

@4zap

This comment has been minimized.

Copy link

commented May 7, 2016

This script made my day! Awesome! :)

@fanto666

This comment has been minimized.

Copy link

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).

@TuningYourCode

This comment has been minimized.

Copy link

commented Feb 7, 2018

Thx for the script :)
Used it to merge munin history (not beautiful at all): https://gist.github.com/TuningYourCode/d1edb8b525bcc46dcafe308c030f742a

@drew-holt

This comment has been minimized.

Copy link

commented May 29, 2018

Worked great for combining nagiosgraph!

simple-rrd-merge.py PING*pl.rrd | rrdtool restore /dev/stdin pl.rrd
@kungfoochef

This comment has been minimized.

Copy link

commented Feb 7, 2019

Thank you for this @arantius, worked perfectly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.