RRDtool is an open source data logging and graphing system well suited for the typical application and embedded environment where µWeb is also expedient. Essentially, RRDtool is two things: a facility to create and store data values; and a facility to graph those values for display. This application note is a small example of how to integrate RRDtool graphs into a µWeb application.
This example does not describe the installation of RRDtool, nor the creation or insertion of values into the RRDtool database. This would normally be performed by your application rather than the web interface. Refer to the RRDtool documentation on how to create and insert to RRDtool database files.
The aim is to produce graphical charts as shown in the following diagram. In this example, we will have two different charts each displaying one or more independent values, with each chart displayable over hour, day, week, or month time frames. Rather than trying to create and manage multiple page files for all these, we will have one main chart.page, with a small subpage for each chart, i.e. chart_temp.page and chart_volts.page.
Most of the page logic is defined in chart.page. The main display scriptlet creates a row of dynamic tabs, one for each of the chart subpages, and then creates a second row of dynamic tabs, one for each time period. Each subpage merely contains a html img tag specifying the subpage which renders itself directly as a raw PNG stream from the the rrdtool graph output.
µWeb RRDtool Interface Tcl Package¶
We have bundled an interface to RRDtool commands into a single rrdgraph.tcl Tcl package which is called by each of the subpages. All RRDtool interaction is performed via this package. It is a reasonably generic example but would likely require some customisation for your application’s specific requirements.