$TimeN) $TimeN = $ptime; $DeltaT = $ptime - $PrevTime; /* Check for time warp and don't include it in our statistics. */ if ($DeltaT > 0 && $DeltaT < 10) { /* Perform RC single-exponential smoothing on the data, to compute a sliding-average rate */ $TimeConstant = 1.0; $decay = exp(-$DeltaT/$TimeConstant); $InstantaneousRate = 1.0/$DeltaT; $AvgRate = ($AvgRate * $decay) + (1.0-$decay)*$InstantaneousRate; if ($AvgRate > $BurstMax) $BurstMax = $AvgRate; /* We will use Time Bins to compute the 95th percentile burst rate, below */ $TimeBin = intval($ptime - $Time1); $BurstRates[$TimeBin] = (int) $AvgRate; /* printf ("%8.4f %10d %10.8f %12.6f\n",$DeltaT,$TimeBin,$decay,$AvgRate); */ $Duration = $TimeBin; /* final time bin is integer duration of sample */ } $PrevTime = $ptime; $answerloc = strpos($line, $panswercount); if (! $answerloc === FALSE) { $answer = substr($line,$answerloc+strlen($panswercount)); } else { $answer = ""; } /* printf ("%20s %15s %1s %15s %s %7d %s\nQuery: %s %s\nReply: %s %d %d %d\n", $ptime, $paddr1, $pdirection, $paddr2, $pudptcp, $pqueryid, $pqidfc, $pqcode, $pqarg, $panswercount, $pna, $pnns, $pnalt); */ $PacketCount++; if ($failed) $FailureCount++; if ($precurse) { $RQcount++; if ($failed) $RQfail++; } if ($pauthorit) $AAcount++; if (array_key_exists($pqcode, $Queries)) { $Queries[$pqcode]++; } else { $Queries[$pqcode] = 1; $QFailures[$pqcode] = 0; } if ($errcode != "") { if (array_key_exists($errcode, $Exits)) { $Exits[$errcode]++; } else { $Exits[$errcode] = 1; } $QFailures[$pqcode]++; } $elapsed = $TimeN - $Time1; if ($elapsed > $IntervalToProcess) break; } /* Compute 95th percentile burst rate by counting down from the maximum burst rate*/ $Percentiles = array(); $Dcount = 0; for ($i=0; $i<=$BurstMax; $i++) {$Percentiles[$i] = 0;}; foreach ($BurstRates as $rate) { $Percentiles[$rate]++; $Dcount++; } $Down5 = 0.05*$Duration; $Sum = 0.0; $Index = intval($BurstMax); while($Sum < $Down5) {$Sum += $Percentiles[$Index--];}; $Burst95 = $Index; /* Print the final summary */ printf ("Start: %s, duration: %1.2f seconds. \n", gmdate("r",$Time1), $elapsed); printf ("%d requests (%1.1f%% failed)\n", $PacketCount, (100*$FailureCount/$PacketCount)); printf ("Avg rate (requests/second) = %1.1f, 95%%ile burst = %1.1f, Max burst = %1.1f\n", $PacketCount / $elapsed, $Burst95, $BurstMax); printf ("%d recursive queries (%1.1f%% failed); %d authoritative replies\n", $RQcount, (100*$RQfail/$RQcount),$AAcount); printf ("%d TCP packets in %d sessions (%d never closed) not analyzed (%1.1f%% of total packets)\n", $TCPcount, $TCPsessions, $TCPsessions-$TCPclosed, 100*$TCPcount/$PacketCount); arsort($Queries, SORT_NUMERIC); print "\nBy type of query in default class:\n"; foreach ($Queries as $what => $count) { if ($what == "CLASS ANY") continue; printf (" %10d/%5.1f%% %-25s %10d failed %8s\n", $count, 100*$count/$PacketCount, $what, $QFailures[$what], sprintf("(%1.1f%%)", 100*$QFailures[$what]/$count)); } if (array_key_exists("CLASS ANY", $Queries)) { print "\nClass ANY:\n"; $what = "CLASS ANY"; $count = $Queries[$what]; printf (" %10d/%5.1f%% %-25s %10d failed %8s\n", $count, 100*$count/$PacketCount, "", $QFailures[$what], sprintf("(%1.1f%%)", 100*$QFailures[$what]/$count)); } arsort($Exits, SORT_NUMERIC); print "\nReturn codes (percentages are of total query count):\n"; foreach ($Exits as $what => $count) { printf (" %10d %5.1f%% %s \n", $count, 100*$count/$PacketCount, $what); } ?>