1<?php 2include('./common.php'); 3 4echo "<html>\n"; 5echo "<!-- RTG Version $VERSION -->\n"; 6echo "<head>\n"; 7 8/* Connect to RTG MySQL Database */ 9$dbc = @mysqli_connect($host, $user, $pass, $db) or 10 die ("MySQL Connection Failed, Check Configuration."); 11 12 if (!isset($PHP_SELF) || ($PHP_SELF == "")) 13 { 14 $PHP_SELF = "95.php"; 15 $customer = isset($_GET['customer'])?$_GET['customer']:""; 16 $syear = isset($_GET['syear'])?$_GET['syear']:""; 17 $eyear = isset($_GET['eyear'])?$_GET['eyear']:""; 18 $smonth = isset($_GET['smonth'])?$_GET['smonth']:""; 19 $emonth = isset($_GET['emonth'])?$_GET['emonth']:""; 20 $sday = isset($_GET['sday'])?$_GET['sday']:""; 21 $eday = isset($_GET['eday'])?$_GET['eday']:""; 22 $shour = isset($_GET['shour'])?$_GET['shour']:""; 23 $ehour = isset($_GET['ehour'])?$_GET['ehour']:""; 24 $smin = isset($_GET['smin'])?$_GET['smin']:""; 25 $emin = isset($_GET['emin'])?$_GET['emin']:""; 26 $debug = isset($_GET['debug'])?$_GET['debug']:""; 27 } 28 29echo "<title>RTG: "; 30if ($customer != "") 31 echo htmlentities($customer) . "\n"; 32?> 33 34</title> 35</head> 36<body bgcolor="ffffff"> 37<a href="http://rtg.sourceforge.net"><img src="rtg.png" border="0" alt="[RTG Home Page]" /></a> 38<p> 39 40<?php 41function cmp($c1, $c2) 42{ 43 return (int)($c2 - $c1); 44} 45 46function int_stats($statement, $dbc) 47{ 48 $counter = $total = 0; 49 $sample_secs = $last_sample_secs = 0; 50 $num_rate_samples =0; 51 $avgrate = $maxrate = $cur_rate = 0; 52 $max = $avg = $nintyfifth = 0; 53 $rate = array(); 54 55 $selectResult = mysqli_query($dbc, $statement); 56 while ($selectRow = mysqli_fetch_object($selectResult)) 57 { 58 $counter = $selectRow->counter; 59 $sample_secs = $selectRow->unixtime; 60 $total += $counter; 61 if (($last_sample_secs > $sample_secs) || 62 (($sample_secs - $last_sample_secs) <= 0) || 63 ($counter < 0)) 64 { 65 echo "*** Bad Samples\n"; 66 echo "*** count: $counter ss: $sample_secs lss: $last_sample_secs\n"; 67 echo "*** stmt: $statement\n"; 68 } 69 if ($last_sample_secs != 0) 70 { 71 $num_rate_samples++; 72 $cur_rate = $counter*8/($sample_secs - $last_sample_secs); 73 array_push($rate, $cur_rate); 74 $avgrate += $cur_rate; 75 if ($cur_rate > $maxrate) 76 $maxrate = $cur_rate; 77 } 78 $last_sample_secs = $sample_secs; 79 } 80 $ignore = round($num_rate_samples * 0.05); 81 usort($rate, 'cmp'); 82 for ($i = 0; $i <= $ignore; $i++) 83 $nintyfifth = $rate[$i]; 84 if ($num_rate_samples != 0) 85 $avg = $avgrate / $num_rate_samples; 86 87 return Array($total,$maxrate,$avg,$nintyfifth,$num_rate_samples,$ignore); 88} 89?> 90 91<hr> 92Report: 95th percentile<br /> 93 94<?php 95echo "<form action=\"$PHP_SELF\" method=\"get\">\n"; 96if (($bt != "" || $smonth != "")) 97{ 98 $dbc = @mysqli_connect($host, $user, $pass, $db) or 99 die ("MySQL Connection Failed, Check Configuration."); 100 /* Format into GNU date syntax */ 101 if ($bt == "") 102 { 103 $bt = strtotime("$syear-$smonth-$sday $shour:$smin:00"); 104 $et = strtotime("$eyear-$emonth-$eday $ehour:$emin:59"); 105 } 106 echo "Customer: " . htmlentities($customer) . "<br />\n"; 107 echo strftime("Period: %m/%d/%Y %H:%M - ", $bt); 108 echo strftime("%m/%d/%Y %H:%M<P>\n", $et); 109 110 $range = "`dtime`>FROM_UNIXTIME(" . mysqli_real_escape_string($dbc, $bt) . 111 ") AND `dtime`<=FROM_UNIXTIME(" . mysqli_real_escape_string($dbc, $et) . ")"; 112 113 $selectQuery = "SELECT `id`,`name`,`description`,`rid` FROM `interface` WHERE " . 114 "`description` LIKE \"%" . mysqli_real_escape_string($dbc, $customer) . "%\""; 115 $selectResult = mysqli_query($dbc, $selectQuery); 116 if (mysqli_num_rows($selectResult) <= 0) 117 echo "<br />No such customer found.<br />\n"; 118 else { 119 while ($selectRow = mysqli_fetch_object($selectResult)) 120 { 121 $ids[$selectRow->id] = $selectRow->name; 122 $rids[$selectRow->id] = $selectRow->rid; 123 $desc[$selectRow->id] = $selectRow->description; 124 } 125 echo "<table border=\"1\">\n"; 126 echo "<tr bgcolor=\"#E0E0E0\">\n"; 127 echo "<th colspan=\"3\">Interface</th><th colspan=\"2\">Current Rate</th><th colspan=\"2\">Max Rate</th><th colspan=\"2\">95th %</th>\n"; 128 if ($debug) 129 echo "<th colspan=\"2\">Samples</th><th colspan=\"2\">Ignore Top</th>\n"; 130 echo "<tr bgcolor=\"#E0E0E0\">\n"; 131 echo "<th>Name</th><th>Description</th><th>Router</th><th>In (Mbps)</th><th>Out (Mbps)</th><th>In</th><th>Out</th><th>In</th><th>Out</th>\n"; 132 if ($debug) 133 echo "<th>In</th><th>Out</th><th>In</th><th>Out</th>\n"; 134 echo "<tr bgcolor=\"#ffffcc\">\n"; 135 $yellow = 1; 136 foreach ($ids as $iid => $name) 137 { 138 $selectQuery = "SELECT `name` FROM `router` WHERE `rid`=" . mysqli_real_escape_string($dbc, $rids[$iid]); 139 $selectResult = mysqli_query($dbc, $selectQuery); 140 $selectRow = mysqli_fetch_object($selectResult); 141 $router = $selectRow->name; 142 143 if ($yellow) 144 $yellow = 0; 145 else 146 $yellow = 1; 147 148 echo "<td>" . htmlentities($name) . "</td>"; 149 echo "<td>" . htmlentities($desc[$iid]) . "</td>"; 150 echo "<td>" . htmlentities($router) . "</td>"; 151 152 $selectQuery = "SELECT `counter`,UNIX_TIMESTAMP(`dtime`) AS `unixtime`,`dtime` FROM " . 153 "`ifInOctets_" . mysqli_real_escape_string($dbc, $rids[$iid]) . "` WHERE $range AND " . 154 "`id`=" . mysqli_real_escape_string($dbc, $iid) . " ORDER BY `dtime`"; 155 list($intbytes_in, $maxin, $avgin, $nfin, $insamples, $inignore) = int_stats($selectQuery, $dbc); 156 $bytesin = round($intbytes_in/1000000); 157 158 $selectQuery = "SELECT `counter`,UNIX_TIMESTAMP(`dtime`) AS `unixtime`,`dtime` FROM " . 159 "`ifOutOctets_" . mysqli_real_escape_string($dbc, $rids[$iid]) . "` WHERE $range AND " . 160 "`id`=" . mysqli_real_escape_string($dbc, $iid) . " ORDER BY `dtime`"; 161 list ($intbytes_out, $maxout, $avgout, $nfout, $outsamples, $outignore) = int_stats($selectQuery, $dbc); 162 $bytesout = round($intbytes_in/1000000); 163 164 printf("<td align=\"right\">%2.2f</td>", $avgin/1000000); 165 printf("<td align=\"right\">%2.2f</td>", $avgout/1000000); 166 printf("<td align=\"right\">%2.2f</td>", $maxin/1000000); 167 printf("<td align=\"right\">%2.2f</td>", $maxout/1000000); 168 printf("<td align=\"right\">%2.2f</td>", $nfin/1000000); 169 printf("<td align=\"right\">%2.2f</td>", $nfout/1000000); 170 if ($debug) 171 echo "<td align=\"right\">$insamples</td><td align=\"right\">$outsamples</td><td align=\"right\">$inignore</td><td align=\"right\">$outignore</td>"; 172 echo "</tr>\n"; 173 if ($yellow) 174 echo "<tr bgcolor=\"#ffffcc\">\n"; 175 else 176 echo "<tr bgcolor=\"#94D6E7\">\n"; 177 } 178 echo "</table>\n"; 179 } 180} else { 181 echo "Customer Name: <input type=\"text\" name=\"customer\"><br />\n"; 182 echo "<p><table>\n"; 183 echo "<tr><td>From: </td>\n"; 184 echo "<td><input type=\"text\" name=\"smonth\" size=3 maxlength=2 value=\""; 185 printf("%02d", date("m")); 186 echo "\" /> / \n"; 187 echo "<input type=\"text\" name=\"sday\" size=3 maxlength=2 value=\""; 188 printf("%02d", (date("d") - 1)); 189 echo "\" /> / \n"; 190 echo "<input type=\"text\" name=\"syear\" size=5 maxlength=4 value=\""; 191 printf("%04d", date("Y")); 192 echo "\" /></td>\n"; 193 echo "<td><input type=\"text\" name=\"shour\" size=3 maxlength=2 value=\""; 194 printf("%02d", date("H")); 195 echo "\" />:\n"; 196 echo "<input type=\"text\" name=\"smin\" size=3 maxlength=2 value=\""; 197 printf("%02d", date("i")); 198 echo "\" /></td></tr>\n"; 199 200 echo "<tr><td>To: </td>\n"; 201 echo "<td><input type=\"text\" name=\"emonth\" size=3 maxlength=2 value=\""; 202 printf("%02d", date("m")); 203 echo "\" /> / \n"; 204 echo "<input type=\"text\" name=\"eday\" size=3 maxlength=2 value=\""; 205 printf("%02d", date("d")); 206 echo "\"> / \n"; 207 echo "<input type=\"text\" name=\"eyear\" size=5 maxlength=4 value=\""; 208 printf("%04d", date("Y")); 209 echo "\" /></td>\n"; 210 echo "<td><input type=\"text\" name=\"ehour\" size=3 maxlength=2 value=\""; 211 printf("%02d", date("H")); 212 echo "\" />:\n"; 213 echo "<input type=\"text\" name=\"emin\" size=3 maxlength=2 value=\""; 214 printf("%02d", date("i")); 215 echo "\" /></td></tr>\n"; 216 echo "<tr><td>Debug: </td>\n"; 217 echo "<td><input type=\"checkbox\" name=\"debug\" /></td></tr>\n"; 218 echo "</table>\n"; 219 220 echo "<p><input type=\"submit\" value=\"Ok\" />"; 221} 222 223if ($dbc) 224 mysqli_close($dbc); 225echo "</form>\n"; 226?> 227<br /> 228<hr /> 229<font face="Arial" size="2"> 230<?php 231 print "<a href=\"http://rtg.sourceforge.net\">RTG</a> Version $VERSION</font>"; 232?> 233</body> 234</html> 235