[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Display system monitoring counter on hard-status line?

From: cga2000
Subject: Re: Display system monitoring counter on hard-status line?
Date: Thu, 06 Sep 2007 16:40:06 -0400
User-agent: Mutt/1.5.13 (2006-08-11)

On Wed, Sep 05, 2007 at 08:25:54PM EDT, Karl. wrote:
> On Wed, Sep 05, 2007 at 04:47:01PM -0400, cga2000 wrote:
> I updated my website a bit and put the whole lua script online, just in 
> case you feel like seeing it more in context.

Not a bad script, but I prefer the cat!

> > If you sample CPU activity every second and find process A used the 
> > CPU .02 seconds and process B .01 second and nothing else was 
> > dispatched during that time frame .. that would add up to 3% CPU ..  
> > with the CPU idle 97% of the time.
> Seems reasonable.  Of course there will be buckets of background 
> processes using cpu time as well as what I assume are your foreground A 
> + B.  Note that ideally you need to calculate time elapsed between 
> samples (as my script does) in case the scheduling of your sampling is 
> not exactly every 1s, otherwise you may find yourself going over 100% 
> apparent usage...

Sure, the above was not meant to be a real-life situation.  Just trying
to prove to myself I understand the concept.

> You can also look at /proc/loadavg for cpu usage info, but I find that 
> it doesn't tell me what I really want to know.  My primary interest in 
> load is for those times when the computer seems to be unresponsive and I 
> want to know if it is cpu-bound or i/o-bound or whatever.  In which 
> case, a 1-minute average is of no use.
> In case you haven't noticed, 'man proc' tells you much about what you 
> can find in the proc filesystem.  (you can read the manpage online:

Thank you!

> > Not sure why my "ps" + "add up what's in the %CPU column" does not 
> > give me the same results as the usual suspects, though.
> Are you including *all* processes in your ps?  Don't forget rounding 
> errors too.

Moot point, since I was unable to combine screen's backtick with a pipe.

In any event, it was a _lot_ more fun doing it in awk 

:-( :-( :-(

Anyway for those still holding their breath,  this is what I came up

backtick 3 0  0  awk 'BEGIN {file = "/proc/stat"; \
while (a==a) \
{getline < file;u=$2-up;s=$3-sp;n=$4-np;i=$5-ip; \
printf ("CPU: %2.1f\n"),(u+s)/(u+s+n+i)*100; \
up=$2;sp=$3;np=$4;ip=$5; \
close(file);system("sleep 1")}}'

Removing the backslashes and joining the above 6 lines should give you
back the original. I haven't been able to figure out how to split lines
in a .screenrc.


This one-liner reads /proc/stat/'s first line every second, computes
the delta between successive values of $2-$5 and prints:

   (duser+dsystem) / (duser+dsystem+dnice+didle) * 100

.. where duser, etc.. are the user delta .. etc.
Since your web site suggests you know a bit more about monitoring the
system :-) !!! ..  I would appreciate if you could confirm my algorithm
is correct. 

I ran it next to conky in different windows and despite the fact I
couldn't control the separate sampling I had a distinct feeling they
were giving roughly the same results.

One minor annoyance is that I haven't found a simple way to make the
display of my %2.1f CPU percentage add a leading white space when the
result of my calculation is < 10.0 .. and this makes my display jump
about every once in a while.  Guess I need to grab the "C" language
printf man page.  This is so distracting that if I can't find a way
round this rapidly, I'll just test whether the result is < 10.0 and add
an intervening' print " ".  

> > > A completely different approach, which I used briefly but abandoned 
> > > for various reasons, is to run conky in stdout mode.  In this mode 
> > > you can set up all sorts of status monitors and have it spit them 
> > > out on stdout, ready to be piped into something.
> > 
> > Not familiar with this mode.  
> > 
> > OTOH, the reason I'm adding some monitoring to screen is that I'm
> > dumping conky .. the overhead mostly.  So ..
> Same here.  Conky is pretty, but if you're only using it to output text, 
> and not pretty graphics, then other tools start to become more 
> attractive.  I was mostly using PII-400 machines, in which processing 
> power is best not squandered.

Even on a PIII-650 it was so "active" that on my idle laptop it ended
up monitoring itself and driving up my CPU's temperature to 70C+!

Shades of Werner Heisenberg?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]