Skip to content

Instantly share code, notes, and snippets.

@mindsocket
Created November 21, 2012 01:12
Show Gist options
  • Save mindsocket/4122420 to your computer and use it in GitHub Desktop.
Save mindsocket/4122420 to your computer and use it in GitHub Desktop.
Quick script for removing NaN values from rrd files
#!/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