Cacti Beginner's Guide(Second Edition)
上QQ阅读APP看书,第一时间看更新

Basic RRDtool graph creation

Let us begin with the RRD example from the preface and use that RRD file as the basis for our graphs.

A note to Windows users:

The following examples also work for Windows. Simply replace the rrdtool command with the full path to the RRDtool binary. For example, use C:\rrdtool\rrdtool.exe instead of rrdtool.

You will also have to copy the DejaVu font from the rrdtool directory to your Windows Fonts directory.

The supplied code examples that came with this book contain some Perl scripts, which will help in the creation of the RRD file and automatically update it with random data. In order to create the test RRD file, use the following command:

    perl create_rrdfile_linux.pl test.rrd
  

If you have installed the RRDtool to C:\rrdtool you can use the following command for Windows:

    perl create_rrdfile_windows.pl test.rrd
  

Having created the test data, you can now start to generate our first RRDtool-based graph. It is going to be a very simple graph displaying only the pure data.

Execute the following code at the command line interface (CLI) to create your first 500-pixel-wide graph:

    rrdtool graph -w 500 data_image.png \
    --start 1488153600 \
    --end 1488218400 \
    DEF:intspeed=test.rrd:data:AVERAGE \
    LINE2:intspeed#FF0000  
  

This will create the following graph:

So what does this command actually do? Using the command, you defined a start and end time in the Unix time format, and defined the RRD file and dataset you want to plot. You also told RRDtool to draw a two-pixel line (LINE2) using this dataset and store the resulting graph as data_image.png. The RRDtool automatically creates the x axis and y axis for you, and also inserts the time and value description. This is the most basic way of creating a RRDtool-based graph.