jepri has asked for the wisdom of the Perl Monks concerning the following question:

I'm working on a plugin for the Moaning Goat Meter to show the CPU load for solaris. Since I don't know how to extract the CPU load directly (if it is actually possible to do so) I'm using mpstat. The output from mpstat looks like this:


As you can see, there is no indication of when a sample is finished, only the header for the next sample (one second later). I don't seem to have the source for mpstat, and anyway it's not good to require people to recompile their system utilities with a version you provide.

At the current moment, I'm reading it in like this:
while (1){ $_=<CPUSTAT>; last if /CPU/; push @tmp, $_; }

Could someone recommend a better way? This lacks a little style, and is also always 1 second behind. Note that I can't just count the CPUs the first time around because on a Sun, they can change while the program is running.

____________________
Jeremy
I didn't believe in evil until I dated it.

Replies are listed 'Best First'.
Re: Nicer way of reading system monitor's output
by Cine (Friar) on Jul 31, 2002 at 08:18 UTC
      Thanks for the pointer, but it only works on 2.5, 2.6 and 2.7 :( We've got eight on most and nine on one or two.

      ____________________
      Jeremy
      I didn't believe in evil until I dated it.

        Well. Update the module and send the change to the maintainer ;)

        T I M T O W T D I
Re: Nicer way of reading system monitor's output
by jepri (Parson) on Jul 31, 2002 at 07:00 UTC
    Errr... the output of mpstat actually looks more like this:
    CPU minf mjf xcal  intr ithr  csw icsw migr smtx  srw syscl  usr sys  wt idl
      1    2   0  220    47  300  259   12   30   74    0   288    3   3   1  93
      2    2   0   13   114  104  281   13   32   69    0   267    3   5   1  92
      3    2   0   11   157  149  289   10   34   70    0    74    1   2   1  96
    CPU minf mjf xcal  intr ithr  csw icsw migr smtx  srw syscl  usr sys  wt idl
      1    4   0  260   410  300  317   30   39   79    0 17480    5   6   0  89
      2    0   0    8   149  103  228   44   36   54    0 65355   13  31   0  56
      3    0   0   18   140  110  284   34   47   93    0 76508   26  23   0  51
    CPU minf mjf xcal  intr ithr  csw icsw migr smtx  srw syscl  usr sys  wt idl
      1    0   0  263   402  300  270   30   54   73    0 62976   15  25   0  60
      2    0   0    4   142  100  270   39   42   94    0 63749   14  26   0  60
      3    0   0   14   145  113  276   32   51   75    0 32621   19  17   0  64
    

    ____________________
    Jeremy
    I didn't believe in evil until I dated it.