home *** CD-ROM | disk | FTP | other *** search
- #include <rpcsvc/rstat.h>
- #include <sys/dk.h>
- #include <ctype.h>
- #include <stdio.h>
-
- #define SLPDEFAULT 10
- #define sane(x) ((x) > 100000 ? (-1) : (x))
- #define scale(x) sane(secs == 1 ? (x) : (x) / secs)
- #define sleep(x) usleep(1000000 * (x))
-
- char **hosts;
- struct statstime *orig;
- int secs;
- int n;
-
- main(ac, av)
- char **av;
- {
- int i;
- char *calloc();
-
- for (i = 1; i < ac && !isdigit(av[i][0]); i++)
- ;
- hosts = (char**)calloc(i, sizeof(char *));
- orig = (struct statstime*)calloc(i, sizeof(struct statstime));
-
- /*
- * Go through it once to fire up all the rstatd's.
- */
- for (i = 1; i < ac; ++i) {
- fprintf(stderr, "%s ", av[i]);
- if (rstat(av[i], &orig[i - 1]) == 0) {
- hosts[n++] = av[i];
- }
- }
- fprintf(stderr, "\n");
- for (i = 1; i < ac; ++i) {
- if (!hosts[i])
- continue;
- rstat(av[i], &orig[i - 1]);
- }
- /*
- * Initialize
- */
- sleep(secs = 1);
- for (i = 0; i < ac - 1; ++i) {
- if (!hosts[i])
- continue;
- dohost(i);
- }
- secs = isdigit(av[ac - 1][0]) ? atoi(av[ac -1]) : SLPDEFAULT;
- while (1) {
- sleep(secs);
- for (i = 0; i < ac - 1; ++i) {
- if (!hosts[i])
- continue;
- dohost(i);
- }
- }
- }
-
- dohost(i)
- {
- struct statstime st;
- static count;
-
- if (count++ % n == 0) {
- printf("%8.8s %4s %4s %4s %3s %3s %3s %3s %3s ",
- "host", "load", "ipkt", "opkt", "err",
- "d0", "d1", "d2", "d3");
- printf("%3s %3s %4s %5s ",
- "ipg", "opg", "intr", "cs");
- printf("%3s %3s %3s\n", "usr", "sys", "idl");
- }
- if (rstat(hosts[i], &st) != 0) {
- perror(hosts[i]);
- exit(1);
- }
- printf("%8.8s %4.1f %4d %4d %3d %3d %3d %3d %3d %3d %3d %4d %5d ",
- hosts[i],
- scale(st.avenrun[0] / 256.),
- scale(st.if_ipackets - orig[i].if_ipackets),
- scale(st.if_opackets - orig[i].if_opackets),
- scale((st.if_collisions + st.if_oerrors) -
- (orig[i].if_collisions + orig[i].if_oerrors)),
- scale(st.dk_xfer[0] - orig[i].dk_xfer[0]),
- scale(st.dk_xfer[1] - orig[i].dk_xfer[1]),
- scale(st.dk_xfer[2] - orig[i].dk_xfer[2]),
- scale(st.dk_xfer[3] - orig[i].dk_xfer[3]),
- scale(st.v_pgpgin - orig[i].v_pgpgin),
- scale(st.v_pgpgout - orig[i].v_pgpgout),
- scale(st.v_intr - orig[i].v_intr),
- scale(st.v_swtch - orig[i].v_swtch),
- 0);
- printf("%3d %3d %3d\n",
- scale(st.cp_time[0] - orig[i].cp_time[0]),
- scale(st.cp_time[2] - orig[i].cp_time[2]),
- scale(st.cp_time[3] - orig[i].cp_time[3]));
- orig[i] = st;
- }
-