[rrd-users] formatting the rrdtool graph commands/scripts

Simon Hobson linux at thehobsons.co.uk
Thu Nov 2 13:08:19 CET 2017

Andreas Schuldei <andreas+rrdtool at schuldei.org> wrote:

> Hi,
> I am looking for inspiration for formatting my rrdtool graph commands.
> given that this is some form of prgramming, i would like to extract common parts like the preamble which is similar in many of my graphs, or format the script so the meaning becomes more obvious. Many of my graph commands are longish (80lines) and are hard to grock after a while. How do you deal with this?

A lot of my graphs are (CGI) script generated, using parameters for timescale etc. So parsing options (eg day, week, month, year) from the HTML request and setting (eg) the start and end accordingly. Some of the scripts (eg traffic by IP address) loop through a number of items building a stacked graph.

In one script I might have one function to generate the common preamble/header, a number of functions to generate graph bodies, and one to generate the trailer - and the output from them is piped through rrd_cgi. Along these lines :

do_header () {
  echo "graph title=${title} start=${start} ....

And finally :
( do_header
  do_footer ) | rrd_cgi 2>/dev/null > ${graphfile}

But in reality, there are lots of ways to do it - which is best for you depends on your requirements, skills, and what's already installed on the system.

More information about the rrd-users mailing list