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

Adding a threshold line to the graph

Now, let us also set a threshold and display a line marking the threshold on the graph. This can be achieved by using the HRULE item. You are going to set a threshold at 50 and use a light-gray color to display it on the graph. The following command creates this line and also adds an additional entry to the legend. In addition, you are also going to change the LINE2 item to an AREA item, so the data being displayed is shown as a filled area:

    rrdtool graph -w 500 data_image.png --start 1488153600 --end     
1488218400 \
--vertical-label bps --title "Interface Speed" \ DEF:intspeed=test.rrd:data:AVERAGE \ HRULE:50#C0C0C0FF:"Threshold ( 50 )\n" \ AREA:intspeed#FF0000:"Interface eth0" \ GPRINT:intspeed:LAST:"Current\:%8.0lf" \ GPRINT:intspeed:AVERAGE:"Average\:%8.0lf" \ GPRINT:intspeed:MAX:"Maximum\:%8.0lf\n"

You can see the light-gray line being printed horizontally on the image, providing a good overview of the time that the data exceeded the threshold:

Using the newline character \n in the description string for the HRULE item allows you to add manual line breaks to the legend section. As you can see in the graph, the following text items are added to the next line.