#!/usr/local/bin/perl
while (<>)
{
  chop;
  split;
  $mmdd = "$_[0] $_[1]";
  if ($mmdd ne $oldmmdd)
  {
    if ($oldmmdd ne "")
    {
      &DumpIt;
    }
    $oldmmdd = $mmdd;
  }
  if ($_[5] eq "begin")
  {
    $sessions++;
    if ($_[6] eq "NET") {$byhost{$_[7]}++;}
  }
  $commands{$_[5]}++;
}

if ($mmdd ne "")
{
  $oldmmdd = $mmdd;
  &DumpIt;
}

exit 0;

sub DumpIt
{
  if ($sessions > 10)
  {
    printf "    ph stats $oldmmdd\n\n";
    @k = keys %byhost;
    printf "%d sessions from %d hosts.\n\n",$sessions,$#k;
    $other = $sessions;
    $otherHosts = $#k;
    foreach $h (keys byhost)
    {
      if ($byhost{$h}>100)
      {
	$other -= $byhost{$h};
	$otherHosts--;
        printf "%-25s %d (%d%%)\n",
	  (gethostbyaddr(pack('C4',split('\.',$h)),2))[0], $byhost{$h},
	  ((100 * $byhost{$h}) / $sessions);
      }
    }
    $otherStr = sprintf("other (%d hosts)", $otherHosts);
    printf "%-25s %d (%d%%)\n\n", $otherStr, $other, ((100 * $other)/ $sessions);
    $cmdTotal = 0;
    @j = keys %commands;
    foreach $c (keys commands)
    {
      $cmdTotal += $commands{$c};
    }
    printf "%d commands used %d times\n\n", $#j, $cmdTotal;

    foreach $c (keys commands)
    {
      if ($commands{$c}>5)
      {
        printf "%-15s %6d (%d%%)\n", $c, $commands{$c},
	  (($commands{$c} * 100) / $cmdTotal);
      }
    }
  }
  $sessions = 0;
  %byhost = ();
  %commands = ();
}
