Adding a legend to the graph
Now that you have added some description to the graph, you can go on and also add a legend to it. For this, you are going to use the LAST, AVERAGE, and MAX poller values. The function of the GRPINT item is to add additional graph information to the legend. You are also going to add a description field to the LINE2 item. Adding a description to the LINE or AREA items will automatically create a legend entry for you.
The LAST, AVERAGE, and MAX values are always calculated using the data limited by the start and end time. Therefore, they directly relate to the chart being displayed.
Let us look at the following command:
rrdtool graph -w 500 data_image.png --start 1488153600 --end
1488218400 \ --vertical-label bps --title "Interface Speed" \ DEF:intspeed=test.rrd:data:AVERAGE \ LINE2:intspeed#FF0000:"Interface eth0" \ GPRINT:intspeed:LAST:"Current\:%8.0lf" \ GPRINT:intspeed:AVERAGE:"Average\:%8.0lf" \ GPRINT:intspeed:MAX:"Maximum\:%8.0lf\n"
The resulting image now also contains a small legend at the bottom:
As you can see, the legend was added to the bottom of the graph, expanding its height. By adding a description to the LINE2 line (Interface eth0) the description was automatically placed at the bottom along with the color being used to draw that line. The GPRINT text and values have then been added right after the description. If you want to add some more text to the next line, you need to make sure that the last GRPINT value contains a \n (newline) string at the end.
Although the height is automatically adjusted, RRDtool does not do the same for the width. In case your legend is larger than the graph image, you will have to manually increase the width yourself. This can be achieved using the -width parameter.