3 %service = ( 0, "unspec",
19 local($tm, $days, $h, $m, $s);
23 $days = sprintf("%dd+", $days) if $days = int($tm / (60*60*24));
24 $days = "" unless $days;
25 $tm = $tm % (60*60*24);
26 $h = int($tm / (60*60));
31 return sprintf("%s%02d:%02d:%02d", $days, $h, $m, $s);
35 local($host, $mode) = split("$;" , @_[$[]);
36 local($count, $version, $firsttime) = split("$;" , $_[$[+1]);
39 if (grep($host =~ m/$_/, @ignpat))
41 print "ignored $host ...\n" if $verbose;
47 if (defined($nc{$host}))
55 $nc{$host} = $name = $host;
59 $name = (gethostbyaddr(pack("C4", split(/\./, $host)), 2))[$[];
60 $nc{$host} = $name = $host if ! defined($name);
64 printf ($fmt, ($lastkey eq $host) ? "" : $name, $service{$mode}, $count, $version, &timedelta($firsttime), $firsttime / $count);
68 $hostcnt++ if $lastkey ne $host;
70 $maxtime = $firsttime if $firsttime > $maxtime;
76 while ($ARGV[$[] =~ /^-[nvid]$/)
78 if ($ARGV[$[] eq "-i")
81 push(@ignpat, shift) unless ! defined($ARGV[$[]);
83 elsif ($ARGV[$[] eq "-d")
86 $dir = shift unless ! defined($ARGV[$[]);
88 elsif ($ARGV[$[] eq "-n")
93 elsif ($ARGV[$[] eq "-v")
100 $dir = "/tmp" unless defined($dir);
102 $fmt = "%48s %10s %7d %7d %13s %14.3f\n";
103 $sfmt = "%48s %10s %7s %7s %13s %14s\n";
104 @lbl = ("Host", "Mode", "Count", "Version", "Time active", "Packetinterval");
106 if (!defined($ARGV[$[]))
108 $hostname = `hostname`;
110 unshift(@ARGV, $hostname);
113 foreach $hostname (@ARGV)
115 $dbmfile = $dir . "/monlstats-" . $hostname;
116 $monl = "xntpdc -c 'hostnames no' -c monl $hostname | tail +3 |";
124 print "Monitor Status of $hostname\n\n";
129 open(MONL, $monl) || die("$monl failed $!");
132 } while (! @monlout && $cnt--);
136 print "not available.\n";
140 dbmopen(Clients, $dbmfile, 0644) || die("dbmopen(.., $dbmfile, ...): $!");
146 ($host, $count, $mode, $version, $lasttime, $firsttime) =
147 (@_[$[, $[+2 .. $[+4, $#_-1,$#_]);
149 $Seen{$host, $mode} = 1;
151 if (!defined($Clients{$host, $mode}))
153 if ($lasttime <= $gone)
156 $Clients{$host, $mode} = $New{$host, $mode} = join("$;", $count, $version, $firsttime, $lasttime);
161 ## throw out the old ones
162 if ($lasttime > $gone)
164 $Old{$host, $mode} = $Clients{$host, $mode};
165 delete $Clients{$host, $mode};
169 $Clients{$host, $mode} = join("$;", $count, $version, $firsttime, $lasttime);
174 grep(($Seen{$_} || ($Old{$_} = delete $Clients{$_})), keys(%Clients));
176 if (grep(($tmp = $_ , !grep($tmp =~ m/$_/, @ignpat)), keys(%New)))
178 print "New customers\n";
179 print "-------------\n";
181 grep( &listentry($_, $New{$_}, 1), sort(keys(%New)) );
186 if (grep((!defined($New{$_}) && ($tmp = $_, !grep($tmp =~ m/$_/, @ignpat))), keys(%Clients)))
188 print "Current customers\n";
189 print "-----------------\n";
191 grep( defined($New{$_}) || &listentry($_, $Clients{$_}, 1) , sort(keys(%Clients)) );
195 if (grep(($tmp = $_, !grep($tmp =~ m/$_/, @ignpat)), keys(%Old)))
197 print "Discarded customers\n";
198 print "-------------------\n";
200 grep( &listentry($_, $Old{$_}, 0) , sort(keys(%Old)) );
206 print "\nSummary:\n";
208 printf("Elapsed time: %13s\n", &timedelta($maxtime));
209 printf(" Hosts: %13d\n", $hostcnt);
210 printf(" Packets: %13d\n", $packcnt);
211 printf(" Rate: %13.2f\n", $packcnt / $maxtime) if $maxtime;