head	1.2;
access;
symbols
	RELENG_7_4_0_RELEASE:1.1.1.1.44.1
	RELENG_7_4:1.1.1.1.44.1.0.8
	RELENG_7_4_BP:1.1.1.1.44.1
	RELENG_7_3_0_RELEASE:1.1.1.1.44.1
	RELENG_7_3:1.1.1.1.44.1.0.6
	RELENG_7_3_BP:1.1.1.1.44.1
	RELENG_7_2_0_RELEASE:1.1.1.1.44.1
	RELENG_7_2:1.1.1.1.44.1.0.4
	RELENG_7_2_BP:1.1.1.1.44.1
	RELENG_7_1_0_RELEASE:1.1.1.1.44.1
	RELENG_6_4_0_RELEASE:1.1.1.1.34.1
	RELENG_7_1:1.1.1.1.44.1.0.2
	RELENG_7_1_BP:1.1.1.1.44.1
	RELENG_6_4:1.1.1.1.34.1.0.2
	RELENG_6_4_BP:1.1.1.1.34.1
	RELENG_7_0_0_RELEASE:1.1.1.1
	RELENG_6_3_0_RELEASE:1.1.1.1
	RELENG_7_0:1.1.1.1.0.48
	RELENG_7_0_BP:1.1.1.1
	RELENG_6_3:1.1.1.1.0.46
	RELENG_6_3_BP:1.1.1.1
	RELENG_7:1.1.1.1.0.44
	RELENG_7_BP:1.1.1.1
	RELENG_6_2_0_RELEASE:1.1.1.1
	RELENG_6_2:1.1.1.1.0.42
	RELENG_6_2_BP:1.1.1.1
	RELENG_5_5_0_RELEASE:1.1.1.1
	RELENG_5_5:1.1.1.1.0.40
	RELENG_5_5_BP:1.1.1.1
	RELENG_6_1_0_RELEASE:1.1.1.1
	RELENG_6_1:1.1.1.1.0.38
	RELENG_6_1_BP:1.1.1.1
	RELENG_6_0_0_RELEASE:1.1.1.1
	RELENG_6_0:1.1.1.1.0.36
	RELENG_6_0_BP:1.1.1.1
	RELENG_6:1.1.1.1.0.34
	RELENG_6_BP:1.1.1.1
	RELENG_5_4_0_RELEASE:1.1.1.1
	RELENG_5_4:1.1.1.1.0.32
	RELENG_5_4_BP:1.1.1.1
	RELENG_4_11_0_RELEASE:1.1.1.1
	RELENG_4_11:1.1.1.1.0.30
	RELENG_4_11_BP:1.1.1.1
	RELENG_5_3_0_RELEASE:1.1.1.1
	RELENG_5_3:1.1.1.1.0.28
	RELENG_5_3_BP:1.1.1.1
	RELENG_5:1.1.1.1.0.26
	RELENG_5_BP:1.1.1.1
	v4_2_0:1.1.1.1
	RELENG_4_10_0_RELEASE:1.1.1.1
	RELENG_4_10:1.1.1.1.0.24
	RELENG_4_10_BP:1.1.1.1
	RELENG_5_2_1_RELEASE:1.1.1.1
	RELENG_5_2_0_RELEASE:1.1.1.1
	RELENG_5_2:1.1.1.1.0.22
	RELENG_5_2_BP:1.1.1.1
	RELENG_4_9_0_RELEASE:1.1.1.1
	RELENG_4_9:1.1.1.1.0.20
	RELENG_4_9_BP:1.1.1.1
	RELENG_5_1_0_RELEASE:1.1.1.1
	RELENG_5_1:1.1.1.1.0.18
	RELENG_5_1_BP:1.1.1.1
	RELENG_4_8_0_RELEASE:1.1.1.1
	RELENG_4_8:1.1.1.1.0.16
	RELENG_4_8_BP:1.1.1.1
	RELENG_5_0_0_RELEASE:1.1.1.1
	RELENG_5_0:1.1.1.1.0.14
	RELENG_5_0_BP:1.1.1.1
	v4_1_1b:1.1.1.1
	v4_1_1a:1.1.1.1
	RELENG_4_7_0_RELEASE:1.1.1.1
	RELENG_4_7:1.1.1.1.0.12
	RELENG_4_7_BP:1.1.1.1
	RELENG_4_6_2_RELEASE:1.1.1.1
	RELENG_4_6_1_RELEASE:1.1.1.1
	RELENG_4_6_0_RELEASE:1.1.1.1
	RELENG_4_6:1.1.1.1.0.10
	RELENG_4_6_BP:1.1.1.1
	RELENG_4_5_0_RELEASE:1.1.1.1
	RELENG_4_5:1.1.1.1.0.8
	RELENG_4_5_BP:1.1.1.1
	RELENG_4_4_0_RELEASE:1.1.1.1
	RELENG_4_4:1.1.1.1.0.6
	RELENG_4_4_BP:1.1.1.1
	v4_1_0:1.1.1.1
	RELENG_4_3_0_RELEASE:1.1.1.1
	RELENG_4_3:1.1.1.1.0.4
	RELENG_4_3_BP:1.1.1.1
	RELENG_4_2_0_RELEASE:1.1.1.1
	RELENG_4_1_1_RELEASE:1.1.1.1
	PRE_SMPNG:1.1.1.1
	RELENG_4_1_0_RELEASE:1.1.1.1
	RELENG_4_0_0_RELEASE:1.1.1.1
	RELENG_4:1.1.1.1.0.2
	RELENG_4_BP:1.1.1.1
	v4_0_99b:1.1.1.1
	v4_0_98f:1.1.1.1
	DMILLS:1.1.1;
locks; strict;
comment	@# @;


1.2
date	2008.08.22.15.58.00;	author roberto;	state dead;
branches;
next	1.1;

1.1
date	99.12.09.13.01.06;	author roberto;	state Exp;
branches
	1.1.1.1;
next	;

1.1.1.1
date	99.12.09.13.01.06;	author roberto;	state Exp;
branches
	1.1.1.1.34.1
	1.1.1.1.44.1;
next	;

1.1.1.1.34.1
date	2008.09.04.12.49.54;	author roberto;	state dead;
branches;
next	;

1.1.1.1.44.1
date	2008.09.03.08.49.07;	author roberto;	state dead;
branches;
next	;


desc
@@


1.2
log
@SVN rev 182007 on 2008-08-22 15:58:00Z by roberto

Merge ntpd & friends 4.2.4p5 from vendor/ntp/dist into head.  Next commit
will update usr.sbin/ntp to match this.

MFC after:	2 weeks
@
text
@#!/local/bin/perl

%service = ( 0, "unspec",
	     1, "Active",
	     2, "Passive",
	     3, "Client",
	     4, "Server",
	     5, "Broadcast",
	     6, "Control",
	     7, "Private" );
%nc = ();
@@ignpat = ();
$noname = 0;
$verbose = 0;
$retries = 5;
$lastkey = 0;

sub timedelta {
  local($tm, $days, $h, $m, $s);

  $tm = @@_[$[];
  $days = 0;
  $days = sprintf("%dd+", $days) if $days = int($tm / (60*60*24));
  $days = "" unless $days;
  $tm = $tm % (60*60*24);
  $h  = int($tm / (60*60));
  $tm = $tm % (60*60);
  $m  = int($tm / 60);
  $s  = $tm % 60;

  return sprintf("%s%02d:%02d:%02d", $days, $h, $m, $s);
}

sub listentry {
  local($host, $mode) = split("$;" , @@_[$[]);
  local($count, $version, $firsttime) = split("$;" , $_[$[+1]);
  local($name);

  if (grep($host =~ m/$_/, @@ignpat))
    {
      print "ignored $host ...\n" if $verbose;
      return;
    }

  return if ! $count;

  if (defined($nc{$host}))
    {
      $name = $nc{$host};
    }
  else
    {
      if ($noname)
	{
	  $nc{$host} = $name = $host;
	}
      else
	{
	  $name = (gethostbyaddr(pack("C4", split(/\./, $host)), 2))[$[];
	  $nc{$host} = $name = $host if ! defined($name);
	}
    }

  printf ($fmt, ($lastkey eq $host) ? "" : $name, $service{$mode}, $count, $version, &timedelta($firsttime), $firsttime / $count);

  if (@@_[$[+2])
    {
      $hostcnt++ if $lastkey ne $host;
      $packcnt += $count;
      $maxtime = $firsttime if $firsttime > $maxtime;
    }

  $lastkey = $host;
}

while ($ARGV[$[] =~ /^-[nvid]$/)
  {
    if ($ARGV[$[] eq "-i")
      {
	shift;
	push(@@ignpat, shift) unless ! defined($ARGV[$[]);
      }
    elsif ($ARGV[$[] eq "-d")
      {
	shift;
	$dir = shift unless ! defined($ARGV[$[]);
      }
    elsif ($ARGV[$[] eq "-n")
      {
	shift;
	$noname = 1;
      }
    elsif ($ARGV[$[] eq "-v")
      {
	shift;
	$verbose = 1;
      }
  }

$dir     = "/tmp" unless defined($dir);
$gone     = 60*60*48;
$fmt = "%48s %10s %7d %7d %13s %14.3f\n";
$sfmt = "%48s %10s %7s %7s %13s %14s\n";
@@lbl = ("Host", "Mode", "Count", "Version", "Time active", "Packetinterval");

if (!defined($ARGV[$[]))
  {
    $hostname = `hostname`;
    chop($hostname);
    unshift(@@ARGV, $hostname);
  }

foreach $hostname (@@ARGV)
  {
    $dbmfile = $dir . "/monlstats-" . $hostname;
    $monl = "xntpdc -c 'hostnames no' -c monl $hostname | tail +3 |";
    $hostcnt = 0;
    $packcnt = 0;
    $maxtime = 0;
    %Seen = ();
    %New = ();
    %Old = ();

    print "Monitor Status of $hostname\n\n";

    $cnt = $retries;
    do
      {
	open(MONL, $monl) || die("$monl failed $!");
	@@monlout = <MONL>;
	close(MONL);
      } while (! @@monlout && $cnt--);

    if (! @@monlout)
      {
	print "not available.\n";
	next;
      }

    dbmopen(Clients, $dbmfile, 0644) || die("dbmopen(.., $dbmfile, ...): $!");

    foreach (@@monlout)
    {
      chop;
      split;
      ($host, $count, $mode, $version, $lasttime, $firsttime) =
	  (@@_[$[, $[+2 .. $[+4, $#_-1,$#_]);
      
      $Seen{$host, $mode} = 1;

      if (!defined($Clients{$host, $mode}))
	{
	  if ($lasttime <= $gone)
	    {
	      ## got a new one
	      $Clients{$host, $mode} = $New{$host, $mode} = join("$;", $count, $version, $firsttime, $lasttime);
	    }
	}
      else
	{
	  ## throw out the old ones
	  if ($lasttime > $gone)
	    {
	      $Old{$host, $mode} = $Clients{$host, $mode};
	      delete $Clients{$host, $mode};
	    }
	  else
	    {
	      $Clients{$host, $mode} = join("$;", $count, $version, $firsttime, $lasttime);
	    }
	}
    }

    grep(($Seen{$_} || ($Old{$_} = delete $Clients{$_})), keys(%Clients));

    if (grep(($tmp = $_ , !grep($tmp =~ m/$_/, @@ignpat)), keys(%New)))
      {
	print "New customers\n";
	print "-------------\n";
	printf $sfmt, @@lbl;
	grep( &listentry($_, $New{$_}, 1), sort(keys(%New)) );
	print "\n";
      }

  
    if (grep((!defined($New{$_}) && ($tmp = $_, !grep($tmp =~ m/$_/, @@ignpat))), keys(%Clients)))
      {
	print "Current customers\n";
	print "-----------------\n";
	printf $sfmt, @@lbl;
	grep( defined($New{$_}) || &listentry($_, $Clients{$_}, 1) , sort(keys(%Clients)) );
	print "\n";
      }

    if (grep(($tmp = $_, !grep($tmp =~ m/$_/, @@ignpat)), keys(%Old)))
      {
	print "Discarded customers\n";
	print "-------------------\n";
	printf $sfmt, @@lbl;
	grep( &listentry($_, $Old{$_}, 0) , sort(keys(%Old)) );
	print "\n";
      }

    dbmclose(Clients);

    print "\nSummary:\n";
    print "--------\n";
    printf("Elapsed time: %13s\n", &timedelta($maxtime));
    printf("       Hosts: %13d\n", $hostcnt);
    printf("     Packets: %13d\n", $packcnt);
    printf("        Rate: %13.2f\n", $packcnt / $maxtime) if $maxtime;
    print "\n";
  }
@


1.1
log
@Initial revision
@
text
@@


1.1.1.1
log
@Virgin import of ntpd 4.0.98f
@
text
@@


1.1.1.1.34.1
log
@SVN rev 182752 on 2008-09-04 12:49:54Z by roberto

MFH ntpd 4.2.4p5.

Main difference with the stable/7 merge is that 6.x does not support -lrt and
the corresponding *timer functions.

Approved by:	re (kensmith)
@
text
@@


1.1.1.1.44.1
log
@SVN rev 182716 on 2008-09-03 08:49:07Z by roberto

MFH ntpd 4.2.4p5.

Approved by:	re (kensmith)
@
text
@@

