Created
November 21, 2012 01:12
-
-
Save mindsocket/4122420 to your computer and use it in GitHub Desktop.
Quick script for removing NaN values from rrd files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# Shell usage example: | |
# f=somefile.rrd | |
# rrdtool dump $f > /tmp/$f.xml && /tmp/deNaN.py /tmp/$f.xml > /tmp/$f.xml.new && mv $f{,.bak} && rrdtool restore /tmp/$f.xml.new $f | |
import fileinput | |
import re | |
lastval = '' | |
for line in fileinput.input(): | |
match = re.search(r"<row><v>(.*)<\/v><\/row>", line) | |
if match: | |
match_str = match.group(1) | |
if match_str == 'NaN': | |
line = line.replace('NaN', lastval) | |
else: | |
lastval = match_str | |
print line, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment