Average CPU Usage for multi CPU box.

  • Permalink
  • submit to reddit
  • Email
  • Follow


I have a Solaris 8 system, and I want to write a shell script that
returns only the current average CPU utilisation from 0 - 100% for all
n CPU's on the box, so for a 4 CPU box I want the average of the CPU
utilisations for all 4 CPU's. So if the utilisations were
25,26,27,34, the average  is 28%.

Currently I have been offered a script like this

#!/bin/bash
idle=`vmstat 1 1| grep -v procs | grep -v swap | awk '{print $22}'`
echo "100 - $idle " | bc -l

but vmstat can give a result > 0 for the idle value (it seems to add
up the idles of all CPUs like this.

procs     memory            page            disk          faults
cpu

 r b w   swap  free  re  mf pi po fr de sr s6 sd sd sd   in   sy   cs
us sy id

 0 1 0 61646264 13160960 885 616 665 1420 1452 0 88 0 9 9 11 1354 1050
904 94 49 194

You can see that id value is 194. If I were to use this I'd get a
negative result from the 100 - computation.

It's very important that the answer be 0-100%.

Any ideas?

Dave

0
Reply dave.clarke (1) 5/8/2007 3:41:17 PM

See related articles to this posting

On May 8, 8:41 am, dave.cla...@reflective.com wrote:
> I have a Solaris 8 system, and I want to write a shell script that
> returns only the current average CPU utilisation from 0 - 100% for all
> n CPU's on the box, so for a 4 CPU box I want the average of the CPU
> utilisations for all 4 CPU's. So if the utilisations were
> 25,26,27,34, the average  is 28%.
> Currently I have been offered a script like this
> #!/bin/bash
> idle=`vmstat 1 1| grep -v procs | grep -v swap | awk '{print $22}'`
> echo "100 - $idle " | bc -l
> but vmstat can give a result > 0 for the idle value (it seems to add
> up the idles of all CPUs like this.
> procs     memory            page            disk          faults
> cpu
>  r b w   swap  free  re  mf pi po fr de sr s6 sd sd sd   in   sy   cs
> us sy id
>  0 1 0 61646264 13160960 885 616 665 1420 1452 0 88 0 9 9 11 1354 1050
> 904 94 49 194
> You can see that id value is 194. If I were to use this I'd get a
> negative result from the 100 - computation.
> It's very important that the answer be 0-100%.

I doubt it

> Any ideas?

Didnt we answer this already in another thread today?
If you arent the same poster using another account my bad!

0
Reply gerryt 5/8/2007 4:38:45 PM

On 8 May, 09:38, gerryt <lepsys...@gmail.com> wrote:
> On May 8, 8:41 am, dave.cla...@reflective.com wrote:
>
>
>
>
>
> > I have a Solaris 8 system, and I want to write a shell script that
> > returns only the current average CPU utilisation from 0 - 100% for all
> > n CPU's on the box, so for a 4 CPU box I want the average of the CPU
> > utilisations for all 4 CPU's. So if the utilisations were
> > 25,26,27,34, the average  is 28%.
> > Currently I have been offered a script like this
> > #!/bin/bash
> > idle=`vmstat 1 1| grep -v procs | grep -v swap | awk '{print $22}'`
> > echo "100 - $idle " | bc -l
> > but vmstat can give a result > 0 for the idle value (it seems to add
> > up the idles of all CPUs like this.
> > procs     memory            page            disk          faults
> > cpu
> >  r b w   swap  free  re  mf pi po fr de sr s6 sd sd sd   in   sy   cs
> > us sy id
> >  0 1 0 61646264 13160960 885 616 665 1420 1452 0 88 0 9 9 11 1354 1050
> > 904 94 49 194
> > You can see that id value is 194. If I were to use this I'd get a
> > negative result from the 100 - computation.
> > It's very important that the answer be 0-100%.
>
> I doubt it
>
> > Any ideas?
>
> Didnt we answer this already in another thread today?
> If you arent the same poster using another account my bad!- Hide quoted text -
>
> - Show quoted text -


Sorry Gerry, I can confirm that I am not the author of the other
thread, although he is a colleague, who for other work reasons has had
to bow out.

The problem is that neither of us are UNIX script writers, and as I
explained the mpstat appears to return multiple rows one for each CPU,
and the vmstat, iostat etc seem to return the sum of the usages rather
than the average. So unless I have misread the suggestions, I still
don't think we have a definitive answer.

I am sorry if this is irritating to you, but all our UNIX support (in
Bulgaria) is unavailable at the moment, so I am hoping that someone
out there will take pity on me and give me a chapter and verse answer.

Thanks for taking the time to reply in any case

0
Reply dave 5/8/2007 5:51:58 PM

On May 8, 10:51 am, dave.cla...@reflective.com wrote:
> On 8 May, 09:38, gerryt <lepsys...@gmail.com> wrote:
> > On May 8, 8:41 am, dave.cla...@reflective.com wrote:
> > > I have a Solaris 8 system, and I want to write a shell script that
> > > returns only the current average CPU utilisation from 0 - 100% for all
> > > n CPU's on the box, so for a 4 CPU box I want the average of the CPU
> > > utilisations for all 4 CPU's. So if the utilisations were
> > > 25,26,27,34, the average  is 28%.
> > > Currently I have been offered a script like this
> > > #!/bin/bash
> > > idle=`vmstat 1 1| grep -v procs | grep -v swap | awk '{print $22}'`
> > > echo "100 - $idle " | bc -l
> > > but vmstat can give a result > 0 for the idle value (it seems to add
> > > up the idles of all CPUs like this.
> > > procs     memory            page            disk          faults
> > > cpu
> > >  r b w   swap  free  re  mf pi po fr de sr s6 sd sd sd   in   sy   cs
> > > us sy id
> > >  0 1 0 61646264 13160960 885 616 665 1420 1452 0 88 0 9 9 11 1354 1050
> > > 904 94 49 194
> > > You can see that id value is 194. If I were to use this I'd get a
> > > negative result from the 100 - computation.
> > > It's very important that the answer be 0-100%.
>
> > I doubt it
>
> > > Any ideas?
>
> > Didnt we answer this already in another thread today?
> > If you arent the same poster using another account my bad!- Hide quoted text -
>
> > - Show quoted text -
>
> Sorry Gerry, I can confirm that I am not the author of the other
> thread, although he is a colleague, who for other work reasons has had
> to bow out.
>
> The problem is that neither of us are UNIX script writers, and as I
> explained the mpstat appears to return multiple rows one for each CPU,
> and the vmstat, iostat etc seem to return the sum of the usages rather
> than the average. So unless I have misread the suggestions, I still
> don't think we have a definitive answer.

mpstat may indeed sum all CPUs into one convenient field and it
appears to be an average. I could only easily test this on my
2 CPU workstation though. A snap:
mpstat
CPU minf mjf xcal  intr ithr  csw icsw migr smtx  srw syscl  usr sys
wt idl
  0   80   4  237   464  300  668   95   46   68    0 101634   26
19   0  55
  1   53   2  270  1784  109  644  139   46   24    0 77903   21  14
0  65
vmstat 1 1
 kthr      memory            page            disk          faults
cpu
 r b w   swap  free  re  mf pi po fr de sr s2 s1 s3 sd   in   sy   cs
us sy id
 0 0 0 5587608 1333320 89 133 498 26 26 0 5 11 0 22  6 2248 179581
1312 24 17 60

I get 60 too : >

> I am sorry if this is irritating to you, but all our UNIX support (in
> Bulgaria) is unavailable at the moment, so I am hoping that someone
> out there will take pity on me and give me a chapter and verse answer.

Lately some folks have been multi posting sometimes many times a day
so out came the BOFH - sorry

Nice about awk is it will add a field if its a number and ignore it
otherwise.
My suggestion was to simply use awk and account for the number of
records minus the records that have no data. Using mpstat 1 1.

awks builtins makes finding a field at the end of line simple. Use $NF
Another builtin is NR or number of lines. You can do (NR-1) in the
case of mpstat.
awk has C like constructs like += so its easy to total $NF.
It also handles basic regular expressions.
If vmstat does the averaging for you its even simpler.

I suppose you could do this:
printf `vmstat 1 1| awk '/^ [0123456789]/ {print $NF}'`\\n
to get the average...? sh foo.sh
59
Works for me


0
Reply gerryt 5/8/2007 6:49:05 PM
comp.unix.solaris 25709 articles. 86 followers. Post

3 Replies
515 Views

Similar Articles

[PageSpeed] 47

  • Permalink
  • submit to reddit
  • Email
  • Follow


Reply:

Similar Artilces:

Multi CPU usage ?
Hi again, i have two multiprocessor PCs (Xeon and Pentium 4) and want to use them with lightwave. On both PCs MS Windows 2000 is installed. I try to set up a rendering farm with the two workstations. Is Lightwave using both CPUs by default ? Does Windows 2000 supports multi-cpus ? Thanks for help, many greetings Wolf "Wolf Hermann" <nospam@nit-consultants.de> wrote in message news:MPG.1a9ab82cb7a842cc9896b0@news.btx.dtag.de... > Hi again, > > i have two multiprocessor PCs (Xeon and Pentium 4) and want to use them > with lightwave. On both PCs MS Windows 2000 ...

above average CPU usage
Hi, I have 10g RAC - 2 node cluster. Most of the time the CPU usage range from 50- 60%. Found that using ADDM, some of the queries took most resource. But when I check from sql*plus the response was quicker and the explain plan output was also not bad. Please give me your valuable inputs to troubleshoot. Thanks. "Ravi" <u36659@uwe> wrote in message news:76b886c70d7f9@uwe... > Hi, > > I have 10g RAC - 2 node cluster. Most of the time the CPU usage range from > 50- > 60%. Found that using ADDM, some of the queries took most resource. But > when > I ch...

CPU usage and load average
Hi, My server is an Intel P4 with Hyperthreading. I am running Fedora Core 1, kernel: Linux 2.4.22-1.2174.nptlsmp #1 SMP. When I run top, the result was like this: -- start: top result -- 13:13:31 up 47 days, 22:55, 3 users, load average: 22.27, 24.70, 21.82 137 processes: 128 sleeping, 9 running, 0 zombie, 0 stopped CPU states: cpu user nice system irq softirq iowait idle total 25.6% 0.0% 7.2% 0.0% 0.0% 0.0% 166.8% cpu00 13.4% 0.0% 4.1% 0.0% 0.0% 0.0% 82.4% cpu01 12.3% 0.0% 3.1% 0.0% 0.0% ...

Average CPU load/usage?
Hi ppl, is it possible to read the 1/5/15 mins average CPU load/usage using PDM on W2K? Right now I can get the current load/usage, and then I manually have to compute it if I want the average load/usage over time ... It would be a lot easier and more elegant if they were ready to be read, as on Linux? // Michael ...

CPU and memory usage monitoring of Linux box?
Hi, Who has source code about CPU and memory usage monitoring of Linux box? I prefer C source? Who can tell me where can I see? Have a day. ...

Simulating high cpu usage on multi-core pc
Hello I am creating a test program which basically is just a busy loop to simulate high cpu usage. My PC is multi-core - 2 processors and the max cpu usage I get is 50%. I assume Windows is deciding to run busy loop on just one processor. It is a MFC Windows app. Is there a way I can run a busy loop on both processors? How would I go about that? Angus Angus wrote: > Hello > > I am creating a test program which basically is just a busy loop to > simulate high cpu usage. My PC is multi-core - 2 processors and the > max cpu usage I get is 50%. I assume ...

CPU and memory usage monitoring of Linux box? #2
Hi, Who has source code about CPU and memory usage monitoring of Linux box? I prefer C source? Could someone tell me where can I get? Have a day. Hiya, somez72 wrote: > Who has source code about CPU and memory usage monitoring of Linux > box? I prefer C source? > Could someone tell me where can I get? Take a look at the source of your command line utils, but these days most of that sort of information comes directly from the kernel via the /proc filesystem. For example, try: cat /proc/meminfo The meminfo part, is documented in t...

NtQuerySystemInformation() for CPU usage on multi core/processor systems
I was hoping to get individual CPU usage information from the system using the NtQuerySystemInformation() API. I have tried the following code several times but it gives wrong results. E.g. the structure returned are 48 bytes long e.g. 4 bytes longer than expected. Also on a dual core system the 2nd processor is "dead" e.g. null - on a quad core however CPU's 1 and 3 are "dead" (results are 0). I bet I screwed up somewhere but I honestly can't see the error. Thanks in advance for pointing out my errors ;) PS! The following example code is not very clean. I...

cpu time usage of multi threaded process and single threaded process.
these are 2 programs for matrix multiplication. :- 1st one is implemented using multiple threading and 2nd using single threading. Process' Cpu time for both comes out to be same ..... but should be less for multi threaded process. Plzz help why Cpu time is same.... ? program1 using multiple threading :- #include<signal.h> #include<stdio.h> #include<sys/types.h> #include<unistd.h> #include<pthread.h> #include<time.h> // decleared globally so can be used by all threads through resorce shareing and dont get destroyed on exit of threads...

is there a way of using a Single processor Oracle License on Multi CPU Box
we have a single cpu Oracle 8i EE license. We need to migrate the database to a new box which has 4 cpu's. Is there a way to limit the usage of oracle 1 cpu so that we are not in violation of our license. Any help or pointers on this issue will be very helpful. thanx in advance Jiggaman "jiggaman" <jiggamanrocks@yahoo.com> wrote in message news:1116975179.468081.77820@g44g2000cwa.googlegroups.com... > we have a single cpu Oracle 8i EE license. We need to migrate the > database to a new box which has 4 cpu's. Is there a way to limit the > usage of oracle 1...

Pix 525 v7.1(2) multi context . CPU Usage problem.
I got a problem this morning with the PIX reporting 99% CPU usage on one context. No unusual traffic is occuring and "normal" levels of connections/translations per second and open. Tried easing back on the log level but that didn't do anything. I haven't got any problem passing data or making new connections so the only thing thats bothering me is the report of 99% CPU. I got this from show cpu context all: 5 sec 1 min 5 min Context Name 0.0% 0.0% 0.0% system 0.0% 0.7% 0.2% xxx 100.0% 98.7% 99.5% xxx I thought the system CPU usage was supposed to sh...

testing individual cpu in multi-cpu system
anyone have any advice on tests of individual cpus in multi-cpu systems? what we'd like to do is be able to excercise one or the other cpu to see if we could force a failure. tks, jah -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! -----== Over 100,000 Newsgroups - 19 Different Servers! =----- J. Holly wrote: > anyone have any advice on tests of individual cpus in multi-cpu systems? what > we'd like to do is be able to excercise one or the other cpu to see if we > could force a failure...

multi CPU system 100% CPU useage
Hi I am having a problem with bind 9.4.1 on one of our new machines. The machine has 2 quad core processors and is running Windows 2003 R2. Bind sees the CPUs when starting and logs "found 8 CPUs, using 8 worker threads". About an hour after starting named.exe consumes all available CPU. I have done some RTFM and STFW and with a bit of testing I found that if I start bind either at the command line with the -n1 or by adding -n1 to the "Start Parameters" in the service manager it logs "found 8 CPUs, using 1 worker threads" and while running like this ne...

How to use up cpu cycles in multi-cpu machine
Hi I am creating a testing program on a 2-processor pc. I can create threads using beginthreadex but how would I create a thread per cpu? I tried setting off a thread which basically ran a busy loop but it only ever grounded the CPU to up to 50%. I assume because only one cpu was being exercised. How would I specify the second cpu for another thread to do a similar thing? Angus Angus <anguscomber@gmail.com> wrote: > >I am creating a testing program on a 2-processor pc. I can create >threads using beginthreadex but how would I create a thread per cpu? I >tr...

poor cpu utilization on dual cpu box
--0-1548555918-1066833793=:42168 Content-Type: text/plain; charset=us-ascii Folks, I�m hoping someone can give me some pointers to resolving an issue with postgres and it�s ability to utilize multiple CPUs effectively. The issue is that no matter how much query load we throw at our server it seems almost impossible to get it to utilize more than 50% cpu on a dual-cpu box. For a single connection we can use all of one CPU, but multiple connections fail to increase the overall utilization (although they do cause it to spread across CPUs). The platform is a dual CPU...

two jobs run serial faster on single cpu box than run parallel on dual cpu box true or false?
I'm in the process of requirements gathering for the purchase of several departmental Linux boxes. I've been told by our IT department that they have seen much better performance on single cpu boxes than on similar but dual cpu boxes. In fact they said that a single cpu box would run two jobs back to back faster than the same two jobs running in parallel on the dual cpu box. Does anyone have any similar or opposite experiences? Thanks in advance Steve In article <ZqMfb.47365$vj2.44764@fed1read06>, Steve Matlock wrote: > I'm in the process of requirements...

Relationship between load average and CPU busy or CPU idle
Hi, Is there some kind of relationship between the load average figure and CPU busy / idle percentage ? What I am seeing: On a 2-CPU SPARC box, A load average nearing 2.0 have a very low CPU idle % ( high very busy % ) On a 1-CPU SPARC box, A load average nearing 1.0 have a very low CPU idle % ( high very busy % ) Thus, what I am concluding so far is that a load average nearing N-CPUs will have a very low CPU idle %. Is this a fair statement ? js wrote: > Is there some kind of relationship between the load average figure and CPU > busy / idle percentage ? Yes, there's SOME...

allocation cpu resources on multi cpu sun system
I am a student/EE attending a major university in southern california. My question is reguarding dynamic cpu resource allocation. Currently, we are limited to 12.5% of the total processing power at any given time. The system in question is a 13+ sparcs cpu sun system. When I use some of the chip design software (mentor graphics leonardo), it can take up to 4 hours to finish one task because I am limited to 12.5% cpu power at any given time while idle processes are upwards of 75%. I am up until 4am due to this poor cpu power allocation scheme. I would like to bring this issue up with the ...

Running Windows or Ubuntu on a multi-core CPU is there a way to get the O/S to use only 2 of the CPU's so that the other 2/4/6 CPU's are "free" for programs; in the sense ...
Running Windows or Ubuntu on a multi-core CPU is there a way to get the O/S to use only 2 of the CPU's so that the other 2/4/6 CPU's are "free" for programs; in the sense that those CPU's would have much less context switching and hence be more cache-friendly and pipeline-friendly? -- Regards, Casey Casey Hawthorne <caseyhHAMMER_TIME@istar.ca> writes: > Running Windows or Ubuntu on a multi-core CPU is there a way to get > the O/S to use only 2 of the CPU's so that the other 2/4/6 CPU's are > "free" for programs; in the sense ...

My APP Core dump in multi CPU but ok in single CPU
My APP core dump in multi CPU OS (not only solaris but also windows) but it is ok in single CPU OS (solaris and windows). The stack on solaris10 + gcc is as below =E5=9C=A8=E6=88=91=E7=9A=84=E9=A1=B9=E7=9B=AE=E4=B8=AD=E7=94=A8=E4=BA=86ACE= =EF=BC=8C=E4=B8=8D=E8=BF=87=E5=87=BA=E7=8E=B0=E4=BA=86=E8=87=B3=E4=BB=8A=E9= =83=BD=E8=BF=98=E6=B2=A1=E6=9C=89=E8=A7=A3=E5=86=B3=E7=9A=84=E9=97=AE=E9=A2= =98! =E6=88=91=E7=9A=84ACE=E7=A8=8B=E5=BA=8F=E4=BB=A3=E7=A0=81=EF=BC=8C=E5=9C=A8= =E5=8D=95CPU=E6=B2=A1=E6=9C=89=E9=97=AE=E9=A2=98=EF=BC=8C=E4=BD=86=E5=9C=A8= =E4=B8=A4=E4=B8=AACPU=E4=B8=8B=E5=B0...

does aidaweb run on 16 cpu boxes? or is it stuck on 1 cpu?
curious for example aolserver hunchentoot and racket web server apparently can use 16 cpus from 1 instance.. can smalltalk? aida? ...

need data and logic diagrams for 37 mighty mouse 3000 plus promotional material and parts. we got JUST the little cpu box.. need a spare cpu box for a case open display ( does not need to work but if
need data and logic diagrams for 37 mighty mouse 3000 plus promotional material and parts. we got JUST the little cpu box... need a spare cpu box for a case open display ( does not need to work but if it does that is even better as it will be a spare) , the cabinet tape drive disk drive any promotional material ( gotta love that mouse!) manuals, logic diagrams a 2392 terminal or a few of them.Please let me know what you have available. The more graphics and promotional items we can include in the display the more visually interesting it will be. Also need an HPIB 1600 bpi reel to reel tape...

need data and logic diagrams for 37 mighty mouse 3000 plus promotional material and parts. we got JUST the little cpu box... need a spare cpu box for a case open display ( does not need to work but i
need data and logic diagrams for 37 mighty mouse 3000 plus promotional material and parts. we got JUST the little cpu box... need a spare cpu box for a case open display ( does not need to work but if it does that is even better as it will be a spare) , the cabinet tape drive disk drive any promotional material ( gotta love that mouse!) manuals, logic diagrams a 2392 terminal or a few of them.Please let me know what you have available. The more graphics and promotional items we can include in the display the more visually interesting it will be. Also need an HPIB 1600 bpi reel t...

Multi-cpu machine, ProcessorAffinity, and process spike on wrong CPU question??
We are writing an application that does some heavy spectrometer data acquisition and the machine we ship with the software is a dual CPU Intel based PC. We run Windows XP Pro SP2 there are multiple exe/dll that are part of our software package. We want the data acquisition software to run on one of the CPUs and we want ALL other processes to run on the other CPU. We wrote a service that watches the processes and sets the affinity to the correct cpu CurProc.ProcessorAffinity = (IntPtr)0x0001; the works.......mostly. What I'm seeing is that if I move a window of any run...