LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 04-24-2010, 04:15 PM   #1
ninja master
Member
 
Registered: May 2008
Distribution: funtoo/gentoo amd64 xwrt
Posts: 408

Rep: Reputation: 30
command line cpu utilization


how would one take the mpstat command, and have the idle time subtracted from 100.... then dump said number to a file or preferably print it to command line?

i want my cpu utilization in non robot time and in non robot /proc/loadavg

thats right i want total cpu utilization % printed in bash (why doesnt nix have this in the proc folder?) (why doesnt mp stat have a flag to show total cpu usage and not give me the run around with % kernel is using % user is using % sys % nice??????)

i asked in another thread but they told me to forward x on an xless system. i can see several ways to display cpu utilization but none answering the question and google totally gives the same answer they gave in the other thread.

sar is broken on this machine, and it is non existent on the other.

sar is now broken on the linux from scratch machine also, and mpstat is running strong on it also =)

with this question, i would like to add for SMP users such as myself.... how would one do that same % but instead of system total, %'s run on individual cores.

much thanks LQ, and im one of the top folders on the folding@home team now =)
 
Old 04-24-2010, 04:41 PM   #2
ninja master
Member
 
Registered: May 2008
Distribution: funtoo/gentoo amd64 xwrt
Posts: 408

Original Poster
Rep: Reputation: 30
Code:
#!/bin/bash
# by Paul Colby (http://colby.id.au), no rights reserved ;)
# modified by a drunken penguin to take a simple snapshot of cpu usage

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 "CPU: $DIFF_USAGE%"
exit
i rephrased the problem, and found a bash script....

it was giving constant updates and printing oddly so i modified it to suit my purpose
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
High CPU utilization on only one CPU out of 4 CPUs makam.sreekanth Linux - Kernel 2 09-03-2009 04:12 AM
cpu utilization and cpu load soltanloo Linux - General 1 06-07-2009 02:19 AM
Total CPU utilization returned by "top" command sanpnair Linux - Newbie 1 05-15-2009 12:19 PM
Interpreting cpu line of top command fshim Linux - Newbie 1 12-22-2008 12:40 PM
Linux desktop GUI tool for CPU utilization and bandwidth utilization karimasif Linux - Software 4 03-03-2008 01:09 PM


All times are GMT -5. The time now is 09:20 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration