home *** CD-ROM | disk | FTP | other *** search
- Here's a little program I hacked up the other night to watch when hosts
- went up and down, as well as how their clocks strayed. To find out
- how this thing works, you can do these things:
-
- * read the following description
- * call statmon w/o any args for a usage message
- * type `h' while in the program
- * read the source
-
- I suggest all in that order. If nothing else, the source is
- a decent example of playing with cbreak and echo mode, using
- UDP sockets, using select to multiplex i/o and timeouts, and for
- using the dump operator to greatly speed up start up time.
- It probably won't work very well, if at all, for non-BSD(ish) sites.
-
- Here's what it does: given a list of hosts, which can be read in from
- a file (a simplified ghosts-type file) it tries to talk to the time/udp
- service of their inetd's, and if they go too long without any answer
- after repeated attempts, it considers them down and tells you so. When
- they come back up again, you get a message that this has happened.
- This is better than mere pings, as it requires a coherent inetd to
- answer you and is pretty cheap. The program will also tell you which
- hosts have times that are far astray from your own. The retry,
- timeout, clock tolerance, and sleep interval between sends are all
- command-line configurable. This is all done asynchronously with
- select()s, including your keyboard inputs, which are in cbreak mode.
-
- Porting notes: you'll need the following include files, probably in
- the perl library directory, which you should have generated from the
- corresponding C include files using the makelib program in the perl
- source directory:
-
- sys/errno.h
- sys/socket.h
- sys/ioctl.h
-
- The last one needs a %sizeof array to work right. I put mine
- in sizeof.h in the perl library. Mine happens to look like this.
- Yours, unless you're on a Convex, will almost surely vary.
-
- $sizeof{'char'} = 1;
- $sizeof{'int'} = 4;
- $sizeof{'long'} = 4;
- $sizeof{'float'} = 4;
- $sizeof{'double'} = 8;
- $sizeof{'long long'} = 8;
- $sizeof{'struct arpreq'} = 36;
- $sizeof{'struct ifconf'} = 8;
- $sizeof{'struct ifreq'} = 32;
- $sizeof{'struct ltchars'} = 6;
- $sizeof{'struct pcntl'} = 116;
- $sizeof{'struct rtentry'} = 52;
- $sizeof{'struct sgttyb'} = 6;
- $sizeof{'struct tchars'} = 6;
- $sizeof{'struct ttychars'} = 14;
- $sizeof{'struct winsize'} = 8;
- $sizeof{'struct system_information'} = 12;
- 1;
-
- It also wants getopts.pl and ctime.pl.
-
- If you find yourself with copious quantities of unwanted disk
- space, you can spare yourself the costs of initialization at
- each startup by calling 'statmon -u' to dump the state of the
- program. This will skip all the include files and static init
- code when restarted. I suggest you make sure that the program
- actually runs first, though, before you bother to dump it. Also,
- those are big include files, so your dump will be pretty huge.
-
- --tom
-