Rrdtool
Compile Instrucations
./configure --prefix=/usr/local --enable-perl-site-install make && make install
Graph Generating Options
rrdtool create test.rrd \
--start 920804400 \
DS:speed:COUNTER:600:U:U \
RRA:AVERAGE:0.5:1:24 \
RRA:AVERAGE:0.5:6:10
rrdtool update test.rrd 920804700:12345 920805000:12357 920805300:12363 \ rrdtool update test.rrd 920805600:12363 920805900:12363 920806200:12373 \ rrdtool update test.rrd 920806500:12383 920806800:12393 920807100:12399 \ rrdtool update test.rrd 920807400:12405 920807700:12411 920808000:12415 \ rrdtool update test.rrd 920808300:12420 920808600:12422 920808900:12423 \
rrdtool graph speed.png \
--start 920804400 --end 920808000 \
DEF:myspeed=test.rrd:speed:AVERAGE \
LINE2:myspeed#FF0000
rrdtool graph speed2.png \
--start 920804400 --end 920808000 \
--vertical-label m/s \
DEF:myspeed=test.rrd:speed:AVERAGE \
CDEF:realspeed=myspeed,1000,\* \
LINE2:realspeed#FF0000
rrdtool graph speed3.png \
--start 920804400 --end 920808000 \
--vertical-label km/h \
DEF:myspeed=test.rrd:speed:AVERAGE \
"CDEF:kmh=myspeed,3600,*" \
CDEF:fast=kmh,100,GT,kmh,0,IF \
CDEF:good=kmh,100,GT,0,kmh,IF \
HRULE:100#0000FF:"Maximum allowed" \
AREA:good#00FF00:"Good speed" \
AREA:fast#FF0000:"Too fast"
rrdtool graph speed4.png \
--start 920804400 --end 920808000 \
--vertical-label km/h \
DEF:myspeed=test.rrd:speed:AVERAGE \
CDEF:nonans=myspeed,UN,0,myspeed,IF \
CDEF:kmh=nonans,3600,* \
CDEF:fast=kmh,100,GT,100,0,IF \
CDEF:over=kmh,100,GT,kmh,100,-,0,IF \
CDEF:good=kmh,100,GT,0,kmh,IF \
HRULE:100#0000FF:"Maximum allowed" \
AREA:good#00FF00:"Good speed" \
AREA:fast#550000:"Too fast" \
STACK:over#FF0000:"Over speed"
PHP Graph Generation
<?php
$opts = array( "–start", "-1d", "–vertical-label=B/s",
"DEF:inoctets=net.rrd:input:AVERAGE",
"DEF:outoctets=net.rrd:output:AVERAGE",
"AREA:inoctets#00FF00:In traffic",
"LINE1:outoctets#0000FF:Out traffic\\r",
"CDEF:inbits=inoctets,8,*",
"CDEF:outbits=outoctets,8,*",
"COMMENT:\\n",
"GPRINT:inbits:AVERAGE:Avg In traffic\: %6.2lf %Sbps",
"COMMENT: ",
"GPRINT:inbits:MAX:Max In traffic\: %6.2lf %Sbps\\r",
"GPRINT:outbits:AVERAGE:Avg Out traffic\: %6.2lf %Sbps",
"COMMENT: ",
"GPRINT:outbits:MAX:Max Out traffic\: %6.2lf %Sbps\\r"
);
$ret = rrd_graph("net_1d.gif", $opts, count($opts));
if( !is_array($ret) )
{
$err = rrd_error();
echo "rrd_graph() ERROR: $err\n";
}
echo "<html><head></head><body>\n";
echo "<img src=\"net_1d.gif\">\n";
echo "</body></html>\n";
?>
String Formatting
The text printed below the actual graph can be formatted by appending special escape characters at the end of a text. When ever such a character occurs, all pending text is pushed onto the graph according to the character specified.
Valid markers are: \j for justified, \l for left aligned, \r for right aligned, and \c for centered. In the next section there is an example showing how to use centered formatting.
\n is a valid alias for \l since incomplete parsing in earlier versions of RRDtool lead to this behavior and a number of people has been using it.
Normally there are two space characters inserted between every two items printed into the graph. The space following a string can be suppressed by putting a \g at the end of the string. The \g also ignores any space inside the string if it is at the very end of the string. This can be used in connection with %s to suppress empty unit strings.
GPRINT:a:MAX:%lf%s\g
A special case is COMMENT:\s which inserts some additional vertical space before placing the next row of legends.
If you are using the proportional font in your graph, you can use tab characters or the sequence \t to line-up legend elements. Note that the tabs inserted are relative to the start of the current legend element!
More Info
php script
The script below is that can generate the MRTG like pages on the fly to look like this.




<?php
/*Variable initialization.*/
$rrdname = "/var/www/mrtg/filename.rrd";
$daygraph = "pngday.png";
$weekgraph = "pngweek.png";
$monthgraph= "pngmonth.png";
$yeargraph = "pngyear.png";
/* I dont suggest you to modify listing code below. */
$daystart = "-2000m";
$weekstart = "-12000m";
$monthstart = "-2880000";
$yearstart = "-34560000";
print <<<END
<html>
<head>
<title>Graphs</title>
</head>
<body>
END;
gambar($daygraph, $rrdname, $daystart);
echo "<div align='center'><font face='verdana' size='2'><b>Daily graph</b></font>\n";
echo "<center><img src=images/$daygraph name='Day Graph' alt='Day Graph'></center></div><br />\n";
gambar($weekgraph, $rrdname, $weekstart);
echo "<div align='center'><font face='verdana' size='2'><b>Weekly graph</b></font>\n";
echo "<center><img src=images/$weekgraph name='Week Graph' alt='Week Graph'></center></div><br />\n";
gambar($monthgraph, $rrdname, $monthstart);
echo "<div align='center'><font face='verdana' size='2'><b>Monthly graph</b></font>\n";
echo "<center><img src=images/$monthgraph name='Month Graph' alt='Month Graph'></center></div><br />\n";
gambar($yeargraph,$rrdname,$yearstart);
echo "<div align='center'><font face='verdana' size='2'><b>Yearly graph</b></font>\n";
echo "<center><img src=images/$yeargraph name='Year Graph' alt='Year Graph'></center></div><br />\n";
print <<<END
</body>
</html>
END;
function gambar($png,$rrd, $start)
{
$comm="rrdtool graph images/$png \-c MGRID#ee0000 \-c GRID#000000 --start $start --end now \
--font-render-mode=mono \
DEF:data0=$rrd:ds0:AVERAGE \
DEF:data1=$rrd:ds1:AVERAGE \
CDEF:input=data0,8,* \
CDEF:output=data1,8,* \
CDEF:shading15=input,0.85,* \
CDEF:shading30=input,0.70,* \
CDEF:shading45=input,0.55,* \
CDEF:shading60=input,0.40,* \
CDEF:shading75=input,0.25,* \
CDEF:drn1=LTIME,86400,%,10800,72000,LIMIT,UN,0,input,IF \
CDEF:nightshade=LTIME,86400,%,28800,LT,INF,LTIME,86400,%,61200,GT,INF,UNKN,input,*,IF,IF \
CDEF:ijo=input,100,GT,input,0,IF \
VDEF:ds0pct=input,95,PERCENT \
AREA:ijo#00aF00:\"Incoming traffic in Bits per second\" \
AREA:nightshade#CCCCCCAA::STACK \
AREA:shading15#00bF00 \
AREA:shading30#00cF00 \
AREA:shading45#00dF00 \
AREA:shading60#00eF00 \
AREA:shading75#00fF00 \
LINE1:output#0000FF:\"Outgoing traffic in Bits per second\" \
LINE1:ds0pct#990033:95th \
GPRINT:input:MAX:\"Maximal In\: %6.2lf %Sbps\" \
GPRINT:output:MAX:\"Maximal Out\: %6.2lf %Sbps\l\" \
GPRINT:input:AVERAGE:\"Average In\: %6.2lf %Sbps\" \
GPRINT:output:AVERAGE:\"Average Out\: %6.2lf %Sbps\l\" \
GPRINT:input:LAST:\"Current In\: %6.2lf %Sbps\" \
GPRINT:output:LAST:\"Current Out\: %6.2lf %Sbps\l\" \
";
exec($comm);
}
?>



