home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / perl / tutorial / eg / statmon.README < prev    next >
Encoding:
Text File  |  1990-03-10  |  2.8 KB  |  71 lines

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