Create Plots using rrdtool
Next step for my humidity logger is to get nice plots. Here rrdtool seems to be the tool of choice.
First create a few rrd-files. For example:
rrdtool create humidity.rrd --step 30 \ DS:humidity:GAUGE:120:0:100 \ RRA:AVERAGE:0.5:1:1200 \ RRA:MIN:0.5:12:2400 \ RRA:MAX:0.5:12:2400 \ RRA:AVERAGE:0.5:12:2400
With update every 30 seconds, a GAUGE value from 0 to 100. Additional calculating average, minimum and maximum of the humidity value.
Adding new values for the plot in python using python-rrdtool.
def log_to_rrd(data): values = json.loads(data) dt = time.mktime(datetime.datetime.now().timetuple()) ret = rrdtool.update('humidity.rrd','%d:%f' % (dt, values.get('humidity'))) if ret: print rrdtool.error()
And build a plot for one day:
def graph(): ret = rrdtool.graph( fn, "--start", "-1d", "--lower-limit=0", "--title=Humidity", "--vertical-label=-" + str(cnt) + str(size), "DEF:hum=humidity.rrd:humidity:AVERAGE", "LINE1:hum#0000FF:Humidity\\r", "COMMENT:\\n", "GPRINT:hum:AVERAGE:Avg Humidity\: %2.2lf%S%%", "COMMENT: ", "GPRINT:hum:MAX:Max Humidity\: %2.2lf%S%%\\r")
Final example (with humidity, temperature and calculated dew point):