Variable definition (VDEF)
In contrast to CDEF definitions, which only work for each data point in a graph, a VDEF definition works over the entire dataset. This allows you to calculate different values for the data being displayed and then re-use this value within the different graph items. You are now going to use this function to draw a HRULE element, which displays the current maximum of the data being displayed.
The complete code now looks like this:
rrdtool graph -w 500 data_image.png --start 1488153600 --end
1488218400 \ --vertical-label bps --title "Interface Speed" \ DEF:intspeed=test.rrd:data:AVERAGE \ VDEF:maximum=intspeed,MAXIMUM \ CDEF:isGreen=intspeed,0,50,LIMIT \ HRULE:50#C0C0C0FF:"Threshold ( 50 )\n" \ HRULE:maximum#202020FF:"Maximum of this period\n" \ AREA:intspeed#FF0000:"Over Threshold\n" \ AREA:isGreen#00FF00:"Interface eth0" \ GPRINT:intspeed:LAST:"Current\:%8.0lf" \ GPRINT:intspeed:AVERAGE:"Average\:%8.0lf" \ GPRINT:intspeed:MAX:"Maximum\:%8.0lf\n"
Running this code from the command line will create the following graph:
You can see a new dark blue line appearing right at the 62-bps mark, showing the Maximum of this period. You calculated this line using the VDEF definition for maximum and using the entire dataset, then you have used the HRULE element to display the maximum variable on the graph. You can use this new feature in Cacti 1.0 to easily calculate different types of data, such as 95th percentile or simple maximum lines as shown previously.