screen-users
[Top][All Lists]
Advanced

[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: Wed, 05 Sep 2007 16:47:01 -0400
User-agent: Mutt/1.5.13 (2006-08-11)

On Wed, Sep 05, 2007 at 01:01:12AM EDT, Karl. wrote:
> On Wed, Sep 05, 2007 at 12:13:19AM -0400, cga2000 wrote:
> > As to %CPU, I couldn't find anything useful in /proc,   ...SNIP...
> 
> This isn't quite directly useful, 

.. course it does.

lua looks a bit more like a regular programming language than awk any
day.

:-)

> but here's a snippet of lua code I use 
> for getting cpu usage for the status bar of my window manager:
> 
>     f=io.open('/proc/stat','r')
>     s=f:read('*l')
>     f:close()
> 
>     _, _, t_usr, t_nice, t_sys, t_idle = string.find(s, 
> "^cpu%s+(%d+)%s+(%d+)%s+(%d+)%s+(%d+)")
>     t_total = t_usr + t_nice + t_sys + t_idle
>     t_step_jiffies = t_total - t_total_prev
>     c_used = 1 - (t_idle - t_idle_prev) / t_step_jiffies
>     t_total_prev, t_idle_prev = t_total, t_idle

I guess if this algorithm is good enough for you.. should be good
enough for me.  

Just need to "reverse-engineer" the above, right?

> It reads a bunch of values from the /proc/stat line that starts with 
> 'cpu', then it has to figure the total time elapsed (t_total), and then
> time elapsed since last we ran the calculation (t_step_jiffies).  Then 
> we can figure out what the cpu usage was (c_used).  Lastly we store away 
> the current values for use next time we run the calculation.

Yes, 

It looks like I'm becoming confused in my old age.

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.

Am I correct?

> (hopefully I haven't edited out anything relevant from the snippet, or 
> even completely messed it up!)
> 
> So, what I'm trying to say, is that I don't know a quick one-stop way to 
> get cpu usage from proc.  

Nor should there be.  

Since this information is only useful to the user/admin who would like
to have some kind of warning in the event of a runaway process causing
trouble for instance.  

Typical user-space stuff, I would imagine..?

> Furthermore, there are slightly different views of what 'cpu usage' 
> means - it seems that some usage displays don't include t_nice, I think 
> because that time is somewhat available to the user rather than the 
> processor being busy and you not being able to do anything about it.  
> (am I making any sense?)

Even sounds like for the finer details, which kernel you are running
might make a difference?

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.

> > I'm also looking for something that would help monitor network traffic 
> > .. Not sure this makes sense, but I was thinking something that 
> > displays UP/DOWN Kb's, maybe?
> > 
> > Not sure where I could get that from.
> 
> have a look at /proc/net/dev
> 
> 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 ..

Thanks.




reply via email to

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