Re: [wmii] Adding cpu usage to status bar

From: fugou nashi <fugounashi+wmii_AT_gmail.com>
Date: Wed, 6 May 2009 17:49:31 +0900

> 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
    ) &
Received on Wed May 06 2009 - 08:49:31 UTC

This archive was generated by hypermail 2.2.0 : Wed May 06 2009 - 09:00:09 UTC