php RRD Graph floating values instead of integers -
i producing rrd graph , facing 2 problems.
problem 1: numbers printing integers without decimals, although when printed decimals appear. confusing. looked online on rrdgraph_graph , although using correct syntax , not applying calculations still floating values instead of integers.
according official website: %s place after %le, %lf or %lg. replaced appropriate si magnitude unit , value scaled accordingly (123456 -> 123.456 k).
i have attached photo sample of output. have provide working example code if understands rrd's can view possible error.
problem 2: trying add on graph vrule:time#color[:legend][:dashes[=on_s[,off_s[,on_s,off_s]...]][:dash-offset=offset]]
function , based on online instructions can supply time. since graph shifting planning time (value) - 1800 sec. wanted place vertical line in middle of graph view approximately average on 30 minutes values. when applying such format error:
<b>graph error: </b>parameter '1400274668-1800' not represent time in line vrule:1400274668-1800#0000cd:half way values
when remove subtraction work fine. there way produce line in middle of graph?
<?php $file = "snmp"; $rrdfile = dirname(__file__) . "/".$file.".rrd"; $in = "losses"; $png = "/home/linux/desktop/"; $in_min = "vdef_in_min"; $in_max = "vdef_in_max"; $in_lst = "vdef_in_lst"; $in_av = "vdef_in_av"; $title = "losses rrd::graph"; $output = array("1h","1d"); $step = 5; $heartbeat = 2 * $step; while (1) { sleep (1); $options = array( "--start","now -15s", "--step", "".$step."", "ds:".$in.":gauge:".$heartbeat.":0:u", "rra:last:0.5:1:3600", "rra:min:0.5:1:3600", "rra:max:0.5:1:3600", "rra:average:0.5:6:600", "rra:last:0.5:300:288", "rra:min:0.5:300:288", "rra:max:0.5:300:288`", "rra:average:0.5:600:144" ); if ( !isset( $create ) ) { $create = rrd_create( "".$rrdfile."", $options ); if ( $create === false ) { echo "creation error: ".rrd_error()."\n"; } } $t = time(); $losses = rand(0, 150); $update = rrd_update( "".$rrdfile."", array( "".$t.":".$losses."" ) ); if ($update === false) { echo "update error: ".rrd_error()."\n"; } date_default_timezone_set('europe/stockholm'); $timezone = new datetime(null, new datetimezone('europe/stockholm')); $date = date('l js \of f y h\\:i\\:s a' , $timezone->format('u')); $comment = "rrd last updated:".$date; $comment = str_replace( ":", "\\:", $comment ); $graph = "graph last updated:".$date; $graph = str_replace( ":", "\\:", $graph ); foreach ($output $test) { $final = array( "--start","end - ".$test."", "--end", "".$t."", "--title=".$file." rrd::graph - ".$test." periods", "--vertical-label=bytes(s)/sec", "--right-axis-label=latency(ms)", "--alt-y-grid", "--rigid", "--width", "800", "--height", "500", "--lower-limit=0", "--no-gridfit", "--slope-mode", "def:".$in."_def=".$file.".rrd:".$in.":last", "cdef:inbytes=".$in."_def", "vdef:".$in_lst."=inbytes,last", "vdef:".$in_min."=inbytes,minimum", "vdef:".$in_max."=inbytes,maximum", "vdef:".$in_av."=inbytes,average", "comment:\\n", "line2:".$in."_def#ff0000:".$in."", "gprint:".$in_min.": minimum\:%6.2lf %s", "gprint:".$in_max.":maximum\:%6.2lf %s", "gprint:".$in_lst.":last\:%6.2lf %s", "gprint:".$in_av.":average\:%6.2lf %s", "comment:\\n", "vrule:".$t."#0000cd:half way values", "comment:\\n", "hrule:50#ffff00:maximum value", "comment:\\n", "comment: ", "comment:\\n", "comment:".$comment."\\r", "comment:".$graph."\\r" ); $outputpngfile = rrd_graph( "".$png."".$test.".png", $final ); if ($outputpngfile === false) { echo "<b>graph error: </b>".rrd_error()."\n"; } } $debug = rrd_lastupdate ( "".$rrdfile."" ); if ($debug === false) { echo "<b>graph result error: </b>".rrd_error()."\n"; } var_dump ($debug); } ?>
the answer first problem data normalisation. since not updating rrd precisely on step boundary every time, submitted data values normalised step boundary, resulting in decimal values. understand this, read alex van den bogeardt's excellent article on subject.
your second problem cannot use vrule declaration in way. first parameter vrule may either number or vdef variable, cannot formula. therefore, vrule:12345678#0000cd:foo
fine, vrule:vdefname#ff00ff:bar
. may not use vrule:123456-123#0000cd:no
. calculation before, this:
"vrule:".($t-1800)."#0000cd:half way values",
... , should result in valid syntax.
Comments
Post a Comment