I’ve been working with RRDTool graphs a lot for the past few days and noted a couple of nice tips for myself which I want to share here:
Graphing Real Numbers as Integers
Sometimes your database contains number in real format (ex: 4.23) and you want to see only integer values on the graphs. For example the database keeps track of number of users sessions and computes AVERAGE, but since having 2.123 sessions number is not that nice (for me at least in this case), it is possible to round it up to integer and have 2 (or 3 if the original real number was more or equal to 2.5). For this, in the graph definition, you need to create a variable to store integer as follows (hate this postfix notation type):
CDEF:var_int=var_real,1,%,0.5,GE,var_real,CEIL,var_real,FLOOR,IF
In normal notation it would look like <code>var_int = (var_real % 1 >= 0.5) ? round_up(var_real) : round_down(var_real)</code> and would round the real var_real number to the upper or lower corresponding integer according to the value after the delimiter. So after such definition you can use var_int for graphing any shapes.
Graphing the Unknowns
It is a good practice to change the background of the graph parts where all variables are unknown. In order to graph such areas I first check if the all variables are defined and if not, I create two other variables, one with value from 0 to -unlimited and second from 0 to +unlimited and display them as AREAs of the same colors. So here we go:
CDEF:u=var1,var2,+,UN,INF,UNKN,IF creates a variable to indicate 0 to +unlimited if the sum of all actual variables is unknown
CDEF:u2=var1,var2,+,UN,NEGINF,UNKN,IF creates a variable for 0 to -unlimited under the same conditions as u.
AREA:u#FFFFB9
AREA:u2#FFFFB9
displays the AREAs with a color I like.
Examples
Let me just post couple of examples of graph definitions here:
<RRD::GRAPH firewall-Net:Traf-LAN.png -w 845 -s <RRD::CV period> -c BACK#FFFFFF -c SHADEA#FFFFFF -c SHADEB#FFFFFF -c FRAME#0000 00 -W 'IT Department' -v "Bits" --title="firewall - LAN Traffic"
DEF:up_rrd=firewall-Net\:Traf-LAN.rrd:up:AVERAGE
DEF:down_rrd=firewall-Net\:Traf-LAN.rrd:down:AVERAGE
CDEF:up=up_rrd,8,*
CDEF:down=down_rrd,8,*
CDEF:down_show=down,-1,*
VDEF:down_min=down,MINIMUM
VDEF:down_ave=down,AVERAGE
VDEF:down_max=down,MAXIMUM
VDEF:up_min=up,MINIMUM
VDEF:up_ave=up,AVERAGE
VDEF:up_max=up,MAXIMUM
COMMENT:' '
COMMENT:' Max'
COMMENT:' Ave'
COMMENT:' Min\n'
COMMENT:' \n'
AREA:down_show#00FF00:'Incomming '
GPRINT:down_max:'%8.2lf%Sb'
GPRINT:down_ave:'%8.2lf%Sb'
GPRINT:down_min:'%8.2lf%Sb\n'
AREA:up#0000FF:'Outgoing '
GPRINT:up_max:'%8.2lf%Sb'
GPRINT:up_ave:'%8.2lf%Sb'
GPRINT:up_min:'%8.2lf%Sb\n'
CDEF:u=up,down,+,UN,INF,UNKN,IF
CDEF:u2=up,down,+,UN,NEGINF,UNKN,IF
AREA:u#FFFFB9
AREA:u2#FFFFB9
>
The above definition is for traffic monitoring
<RRD::GRAPH firewall-Net:Conn.png -l 0 -w 380 -s <RRD::CV period> -c BACK#FFFFFF -c SHADEA#FFFFFF -c SHADEB#FFFFFF -c FRAME#000000 -W 'IT Department' -v "Connections" --title="firewall - Established TCP Connections"
DEF:total=firewall-Net\:Conn.rrd:total:AVERAGE
CDEF:total_show=total,1,%,0.5,GE,total,CEIL,total,FLOOR,IF
VDEF:total_min=total,MINIMUM
VDEF:total_ave=total,AVERAGE
VDEF:total_max=total,MAXIMUM
COMMENT:' '
COMMENT:' Max'
COMMENT:' Ave'
COMMENT:' Min\n'
COMMENT:' \n'
AREA:total_show#0000FF:'Connections '
GPRINT:total_max:'%10.0lf'
GPRINT:total_ave:'%10.0lf'
GPRINT:total_min:'%10.0lf\n'
CDEF:u=total,UN,INF,UNKN,IF
CDEF:u2=total,UN,NEGINF,UNKN,IF
AREA:u#FFFFB9
AREA:u2#FFFFB9
>
And this one is showing the number of established TCP connections.
Note that both graphs use the <RRD::CV period> as a definition of the beginning of the graph period. I use this when viewing the graph by supplying the ?period=-1h or similar to display the graphs for different time periods.