[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: |
Karl. |
Subject: |
Re: Display system monitoring counter on hard-status line? |
Date: |
Wed, 5 Sep 2007 17:01:12 +1200 |
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, 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
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.
(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.
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?)
> 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.
Karl.
--
http://mowson.org/karl
Re: Display monitoring counterx on status line? [SOLVED], cga2000, 2007/09/07