#!/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() |
This comment has been minimized.
This comment has been minimized.
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. |
This comment has been minimized.
This comment has been minimized.
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 ? many thanks, |
This comment has been minimized.
This comment has been minimized.
Thanks a lot, works like a charm |
This comment has been minimized.
This comment has been minimized.
Thanks pal for your fantastic work, you saved my life today! |
This comment has been minimized.
This comment has been minimized.
This script made my day! Awesome! :) |
This comment has been minimized.
This comment has been minimized.
This tool does not properly work with RRDs generated by smokeping. |
This comment has been minimized.
This comment has been minimized.
Thx for the script :) |
This comment has been minimized.
This comment has been minimized.
Worked great for combining nagiosgraph!
|
This comment has been minimized.
This comment has been minimized.
Thank you for this @arantius, worked perfectly. |
This comment has been minimized.
This comment has been minimized.
thank you , it is working properly |
This comment has been minimized.
This comment has been minimized.
hi . i use this command as below |
This comment has been minimized.
This comment has been minimized.
i want to merge rrd file because i have gap between out graph |
This comment has been minimized.
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