| 
<?/*******************************
 * Author: Md.Monjurul Hasan
 * Date Created: 26-10-2009
 * Last Modified: 28-10-2009
 *
 * Description - RRD data manipulator
 */
 
 /***************included files*******/
 include ("HelperFunc.php");
 require_once ("rrd_manipulator.php");
 
 //read config file
 if(is_readable('config.php')) {
 require_once('config.php');
 global $mrtg_config, $fixed_pages;
 $rrd_dir = $mrtg_config ['rrd_path'];//get the rrd files path
 $rrds = $mrtg_config['rrd_array'];//get comma separated rrd names from config file
 }
 //variable declaration
 $cur_in ="";
 $cur_out ="";
 $max_in ="";
 $max_out ="";
 $avg_in ="";
 $avg_out ="";
 $helper = new HelperFunc;
 $graph_type = "daily";
 //get rrd array from the comma separated rrd array string of config file
 $each_rrd = split(",",$rrds);
 ?>
 
 <!--- HTML Code -->
 <html>
 <head><title>MRTG-RRDTool Manipulator using PHP</title>
 <meta http-equiv = "Content-Type" content = "text/html; charset = utf-8" />
 <meta http-equiv = "refresh" content = "600;URL = test.php" /> <!-- after 10 mins (10*60), this page is auto refreshed -->
 <link rel="stylesheet" type="text/css" href="datagrid.css" /> <!-- css file -->
 </head>
 <body>
 <div id='main'>
 <h3>RRD Manipulator</h3>
 Daily BW Usage
 <table class='tbl'> <!--table to show output values -->
 <thead><tr>
 <td class='tbl-header'>Client Name</td><td class='tbl-header'>Cur in</td><td class='tbl-header'>Cur out</td><td class='tbl-header'>Avg in</td><td class='tbl-header'>Avg out</td><td class='tbl-header'>Max in</td><td class='tbl-header'>Max out</td><td class='tbl-header'>95% in</td><td class='tbl-header'>95% out</td>
 </thead></tr>
 <tbody>
 <!-- process each rrd -->
 <?
 $count = 0;
 for ($c = 0; $c < count($each_rrd); $c++) {
 $myrrdmrtg = new rrdmrtg($each_rrd[$c]);//call the class
 $ret = $myrrdmrtg->manipulate_rrd($myrrdmrtg->myrrdfile, $graph_type);
 
 $result = $helper->format_bits($ret['current_in']); // result[0] is value and result[1] is Mbps/kbps/Gbps
 $cur_in = $result[0]." ".$result[1];
 
 $result = $helper->format_bits($ret['current_out']);
 $cur_out = $result[0]." ".$result[1];
 
 $result = $helper->format_bits($ret['average_in']);
 $avg_in = $result[0]." ".$result[1];
 
 $result = $helper->format_bits($ret['average_out']);
 $avg_out = $result[0]." ".$result[1];
 
 $result = $helper->format_bits($ret['max_in']);
 $max_in = $result[0]." ".$result[1];
 
 $result = $helper->format_bits($ret['max_out']);
 $max_out = $result[0]." ".$result[1];
 
 $result = $helper->format_bits($ret['percentile_in']);
 $percentile_in = $result[0]." ".$result[1];
 
 $result = $helper->format_bits($ret['percentile_out']);
 $percentile_out = $result[0]." ".$result[1];
 
 ?>
 <tr <? if ($count%2==0) {echo "class='tbl-row tbl-row-even'";} else {echo "class='tbl-row tbl-row-odd'";} ?> >
 <td><?=$each_rrd[$c]?></td><td><? echo $cur_in;?></td><td><? echo $cur_out;?></td></td><td><? echo $avg_in;?></td><td><? echo $avg_out;?></td><td><? echo $max_in;?></td><td><? echo $max_out;?><td><? echo $percentile_in;?></td><td><? echo $percentile_out;?></td>
 </tr>
 <?
 $count++;
 }
 ?>
 </tbody>
 <tfoot>
 <tr class='tbl-footer'>
 <td style='text-align: left'>Total <?echo $count;?> results found</td>
 </tr>
 </tfoot>
 </table>
 </div>
 </body>
 </html>
 
 
 |