You are not logged in.

#1 2009-07-13 18:41:11

oib111
Member
Registered: 2009-06-20
Posts: 87

Displaying CPU Usage and Other Things in Wmii Status Bar

I'm trying to display my CPU usage and other things in the status bar (other things being HDD usage and the current song playing in MOC). The only one of which I know how to do is find the current song playing, but for some reason I can't get it working. I tried making it:

status() {
          $(mocp -i | grep SongTitle) '|' echo -n $(uptime | sed 's/.*://; s/,//g') '|' $(date)
}

That doesn't work, but it's odd because if you place that at the end of that line it works.

Last edited by oib111 (2009-07-13 18:41:32)

Offline

#2 2009-07-13 19:08:16

rusty99
Member
Registered: 2009-03-18
Posts: 253

Re: Displaying CPU Usage and Other Things in Wmii Status Bar

Try moving echo -n to the start of the line.

status() {
             echo -n  $(mocp -i | grep SongTitle) '|' $(uptime | sed 's/.*://; s/,//g') '|' $(date)
}

Offline

#3 2009-07-13 19:25:42

oib111
Member
Registered: 2009-06-20
Posts: 87

Re: Displaying CPU Usage and Other Things in Wmii Status Bar

Thank's that worked, but how do I display the CPU usage and HDD usage?

Offline

#4 2009-07-13 19:50:59

rusty99
Member
Registered: 2009-03-18
Posts: 253

Re: Displaying CPU Usage and Other Things in Wmii Status Bar

Not sure about cpu usage but for hd usage in Gb/Mb you could do

df -h | grep /dev/sda* | awk '{print $3}'

* partition you want to monitor

or substitute 3 for 5 if you want it displayed as a percentage.

Offline

#5 2009-07-13 20:11:36

oib111
Member
Registered: 2009-06-20
Posts: 87

Re: Displaying CPU Usage and Other Things in Wmii Status Bar

Thanks! Maybe I can extract the CPU usage from top using grep ?

Offline

#6 2009-08-05 18:50:43

Shu
Member
From: Russia
Registered: 2009-04-09
Posts: 3

Re: Displaying CPU Usage and Other Things in Wmii Status Bar

#!/bin/bash

PREV_TOTAL=0
PREV_IDLE=0

while true; do
  CPU=(`cat /proc/stat | grep '^cpu '`) # Get the total CPU statistics.
  unset CPU[0]                          # Discard the "cpu" prefix.
  IDLE=${CPU[4]}                        # Get the idle CPU time.

  # Calculate the total CPU time.
  TOTAL=0
  for VALUE in "${CPU[@]}"; do
    let "TOTAL=$TOTAL+$VALUE"
  done

  # Calculate the CPU usage since we last checked.
  let "DIFF_IDLE=$IDLE-$PREV_IDLE"
  let "DIFF_TOTAL=$TOTAL-$PREV_TOTAL"
  let "DIFF_USAGE=(1000*($DIFF_TOTAL-$DIFF_IDLE)/$DIFF_TOTAL+5)/10"
  echo -en "[ Cpu :: $DIFF_USAGE% ]" | wmiir create /rbar/cpu

  # Remember the total and idle CPU times for the next check.
  PREV_TOTAL="$TOTAL"
  PREV_IDLE="$IDLE"

  # Wait before checking again.
  sleep 1
done

Offline

Board footer

Powered by FluxBB