Re: [wmii] Adding cpu usage to status bar
On Wed, May 6, 2009 at 10:49 AM, fugou nashi wrote:
>> Anybody can give a hint at what might be going on, or have a better
>> idea on how to show the cpu % usage?
>
> you should use ps rather than top
> string=`ps -eo pcpu,ucmd --sort -pcpu|tail -n +2|awk 'BEGIN
> {ORS=" "}; $1 > 50 {print $2 " " $1}'`
Hi,
I liked this idea better, so I settled with this:
# Status Bar Info
status() {
echo -n $(acpi) '|' $(ps -eo pcpu,ucmd --sort -pcpu | sed -n
2,4p | awk '$1 > 10 {print $1 " (" $2 ")"}') '|' $(uptime | sed
's/.*://; s/,//g') '|' $(date)
}
I'm showing the first 3 processes if they happen to be using more than 10%.
Thanks to all who contributed to this discussion.
Jesus.
Re: [wmii] Adding cpu usage to status bar
> Anybody can give a hint at what might be going on, or have a better
> idea on how to show the cpu % usage?
you should use ps rather than top
here's my status bar scripts including one that shows all processes
using more than 50% CPU:
(
bar=9batt
while :
do
if acpi_available
then
string=`acpi -b | grep discharging | sed 's/.* \(.*%\),
\(.*\):.*/\1 \2/'`
else
string=`apm | sed 's/.* \(.*%\)/\1/'`
fi
if [ -z "$string" ]
then
wmiir remove /rbar/$bar 2>/dev/null
else
echo "$WMII_NORMCOLORS" | wmiir create /rbar/$bar
echo -n "$string" | wmiir write /rbar/$bar
fi
sleep 60
done
) &
(
clock=8clock
echo "$WMII_NORMCOLORS" | wmiir create /rbar/$clock
while date '+%d %R' | wmiir write /rbar/$clock; do
sleep `expr 60 - \`date '+%S'\``
done
) &
(
log=7log
tail -F /var/log/messages | while read line
do
string=`echo -n $line|cut -d " " -f 5-`
if [ "$string" = "-- MARK --" ]
then
wmiir remove /rbar/$log 2>/dev/null
else
echo "$WMII_NORMCOLORS" | wmiir create /rbar/$log
echo -n "$string" | wmiir write /rbar/$log
sleep 1
fi
done
) &
(
top=3top
while :
do
string=`ps -eo pcpu,ucmd --sort -pcpu|tail -n +2|awk 'BEGIN
{ORS=" "}; $1 > 50 {print $2 " " $1}'`
if [ -z "$string" ]
then
wmiir remove /rbar/$top 2>/dev/null
else
echo "$WMII_NORMCOLORS" | wmiir create /rbar/$top
echo -n "$string" | wmiir write /rbar/$top
fi
sleep 10
done
) &
Re: [wmii] Adding cpu usage to status bar
On Tue, May 05, 2009 at 10:16:18AM -0700, Manuel Rotter wrote:
top -b -d 1 -n 2|grep Cpu|awk 'BEGIN { FS = " " } { print $2 }'|tail
-n 1 | sed 's/us,//g')
This should echo the right cpu usage...top -n 1 seems to be not
right(sometimes?).
We also had another Way of doing it, probably more reliable, but i am
sorry, i can't tell you that. It has to do something with /proc/stat,
but for me this was enough.
The only real problem I have with this is that the wall time of
top -n 1 is ~.5sec on my machine, and it has to compute a lot of
data other than overall CPU utilization. I don't think it's
suitable for a status script when used as such.
--
Kris Maglione
Saying that Java is good because it works on all platforms is like
saying anal sex is good because it works on all genders.
--Unknown
Re: [wmii] Adding cpu usage to status bar
Hey,
You need the '-b' Option for top, because it's not for the Terminal.
We talked long about that in the IRC Channel, we came to this:
top -b -d 1 -n 2|grep Cpu|awk 'BEGIN { FS = " " } { print $2 }'|tail
-n 1 | sed 's/us,//g')
This should echo the right cpu usage...top -n 1 seems to be not
right(sometimes?).
We also had another Way of doing it, probably more reliable, but i am
sorry, i can't tell you that. It has to do something with /proc/stat,
but for me this was enough.
2009/5/5, Jesús Gabriel y Galán :
> Hi,
>
> I was trying to modify the status bar to add cpu % usage. The easiest
> way I found (or so I thought) was this, which works in the command
> line:
>
> je...@localhost:~$ top -n 1 | awk 'NR==3 {print $2}'
> 1.9%us,
>
> (I will massage $2 later to remove the us and the comma, but for now
> it was enough as a test),
> but when I add it like this to my wmiirc:
>
> status() {
> echo -n $(acpi) '|' $(top -n 1 | awk 'NR==3 {print $2}') '|'
> $(uptime | sed 's/.*://; s/,//g') '|' $(date)
> }
>
> it doesn't work. It shows an empty space between the two |. (the
> status function is the one called in the original wmiirc)
> Anybody can give a hint at what might be going on, or have a better
> idea on how to show the cpu % usage?
>
> Thanks,
>
> Jesus.
>
>
