-
-
Save arantius/2166343 to your computer and use it in GitHub Desktop.
#!/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() |
Thank you for this @arantius, worked perfectly.
thank you , it is working properly
hi . i use this command as below
python simple-rrd-merge.py 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
i want to merge rrd file because i have gap between out graph
Hi! Using the tool as below:
./rrd_merge.py var/pnp4nagios/perfdata/host1/CPU_load_load1.rrd CPU_load_load1.rrd | rrdtool restore /dev/stdin merged.rrd
I got this error:
File "rrd_merge.py", 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
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:
https://gist.github.com/m3rlinux/e0ebe1fba39789f27209577cf4a08685
Indeed, this script is over 10 years old and was written for Python 2.
Yes! But it works like a charm with little changes ;)
It works perfect! Thank you!
Worked great for combining nagiosgraph!