Average CPU Usage for multi CPU box.

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
5/8/2007 3:41:17 PM
comp.unix.solaris 25873 articles. 0 followers. Post Follow

3 Replies
761 Views

Similar Articles

[PageSpeed] 28
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
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
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
gerryt
5/8/2007 6:49:05 PM
Reply:
Similar Artilces:

Any External Box That Will Invoke Power Saving On Monitor?
I have an early model PC that does not have power saving features on the monitor. I cannot enable ACPI for the processor under Windows 2000 as well. I would like the monitor to go into a power saving mode after I am done with it, rather than turning it off. Is there any device that: (preferred) a) Would detect no mouse or keyboard activity for N minutes and then put the monitor in power save mode until keyboard or mouse is detected OR b) Would let me manually switch the monitor to power save mode and back on? I have a monitor that is dying slowly and the initial power on sequenc...

Disabling CPU on HP server without rebooting system
Hi, Is it possible to disable CPU without rebooting the system on HP server? IS there a link/document which I can refer to figure out the breakdown of the power consumption by various components in an HP server? TIA, Praveen On the seventh day, Praveen Kumar A wrote... > Is it possible to disable CPU without rebooting the system > on HP server? maybe on the larger NetDomes. On the normal ia32 systems, there's no chance. > IS there a link/document which I can refer to figure out > the breakdown of the power consumption by various components > in an HP serve...

Re: VA7110 LUN usage #6
IIRC, the CommandView SCM will show the space as it is allocated for each LUN. When you create a LUN, the space is not initialized. It just marked that it can go up to a specific amount. As you use the space, it is initialized for that LUN and marked for it. Even if you delete the files in the LUN space, that space is not returned to the "pool" so to speak. It remains allocated for that LUN. Denys -----Original Message----- From: HP-3000 Systems Discussion [mailto:HP3000-L@RAVEN.UTC.EDU]On Behalf Of David N Lukenbill Sent: Monday, February 16, 2004 4:27 PM To: HP3...

Multi Document Interface
Moin, is it possible to design an MDI with GUIDE? Thx, Kai ...

Usage of $input
Hi, I am trying to make my test bench read commands from a file using the $input system task. But simply adding this command along with the file name (that has the commands to run) doesn't seem to be working in Modelsim. The simulator complains that "System task or function $input is not defined". This is the Modelsim PE Student Edition 6.3a. What am I doing wrong? Thanks Kanchan On Oct 3, 1:51 pm, kb33 <kanchan.devarako...@gmail.com> wrote: > Hi, > > I am trying to make my test bench read commands from a file using the > $input system task. ...

RAM-CPU Singularity
One of my computers is very old (PIII 667 MHz, 128 MB RAM, bought in summer 2000) and runs Windows XP SP2. While I'm going to buy some more RAM tomorrow, I have this idea of RAM-CPU singularity: That is to say, software applications should sometimes treat the RAM and CPU resources as one single computing resource, using an idle resource to compensate the urgent needs of another kind of resource. Based on space-time tradeoff principles in algorithm design theory, we can redesign object libraries like STL to be able to adapt to any extremely unbalanced space-time requirements (e.g. a very ...

Average intensity as a function of the angle
Hello, I need to calculate the average intensity value I(xi,yi), of a certain point (xi,yi) in an image I, on a small angular interval [theta-pi/12;theta+pi/12] where the intensity value of a point is xi=10+sin(theta) yi=6+cos(theta) (where the "angle theta" is known). I know that this could be accomplished by integrating the function I(xi,yi) (image intensities) in the interval [theta-pi/12;theta+pi/12] and by then diving the integral by the size of the interval (pi/6). But the image function is not continuous. Do you know how I could calculate the average value of a point...

Xsun consuming a lot of CPU (70%) on Solaris 9 on a SB1500 with VX100 Grafik-card
Hi my Solaris 9 has per default a Xsun Prozess. This is consuming a lot of CPU-Power. Is this a bug, or how can I stop this? For Help Thanks Christoph sputnik136 wrote: > Hi > > my Solaris 9 has per default a Xsun Prozess. This is consuming a lot of > CPU-Power. Is this a bug, or how can I stop this? > > For Help Thanks > Christoph > > Is the screen saver running with eye-candy? Hi No Screen-Saver, This also happens when i am not logged in. Christoph "Another Tom" <thamilt_anda_5@snet.net> schrieb im Newsbeitrag news:S_uVc.1720$Eq1....

How to make "averages of the averages of the data rows" using MySQL query?
Hello, I have a need to create a "nested" query. I have some data in my DB that I first would like to average by time (data lines correspond to each minute and I will have houly averages). But then I need to apply some mathematics to each houly average and then average these again over bigger intervals of time. The question is, how I can do that "two- step" averaging as a MySQL 5 query? The first averaging I know how to do, that is: SELECT TIME, AVG(CORRECTED_COUNTS) FROM PROD_1MIN WHERE TIME <= '2008-06-30 23:59' AND TIME >= '2008-05-01 00:00' GROU...

Browser Multi Select
Hi All, Does anybody know why bBrowser multi select does not allow you to hold down shift key to select AND unselect (highlight) records. For example - if user is tagging/selecting/highlighting a group of records by holding down shift and down arrow and selects too many they cannot just up arrow to deselect the records they dont want. Is there something I need to set up to do this? Regards, Brian. On Wed, 25 Jun 2008 08:29:12 -0700 (PDT), "brian@jotika.co.uk" <brian@jotika.co.uk> wrote: >Hi All, > >Does anybody know why bBrowser multi select d...

while inputs grudgingly treat blues, the coins often murder at the average generations
at both sites were told repeatedly that Internet email was being monitored; this includes all traffic picked up by my JobTalk analytic: > Salomon site. > > All sites start out with the employment contract stating unequivocally > that the systems are the company's and are to be used only for work > purposes. And that they are subject to inspection. You signed it. > > Salomon's goes further by stating the firm's computer systems may be > audited and that they have the right to do so even if you have put > personal information on the system....

FS: HP A5492A Dual CPU Boards
From an Upgrade we have 18pcs HP A5492A Dual CPU Boards w. 2x PA-8500 440MHz. These boards are tested and 100% working. Location is Germany, we ship worldwide. Contact for pricing. We also have lots of HP9000 spare parts. Benjamin Gawert Gawert Technologies sales@gawert-edv.de ...

Computing average of time deltas
Hello, Just to make sure I am not reinventing the wheel(tm) again: is there a function/lib in Ruby which computes average of timespans? e.g. first task took 1s:100ms second task took 1s:400ms third task took 3s:500ms -------- average 2s:000ms TIA, Peter __ http://www.rubyrailways.com :: Ruby and Web2.0 blog http://scrubyt.org :: Ruby web scraping framework http://rubykitchensink.ca/ :: The indexed archive of all things Ruby On Mar 19, 5:58 am, Peter Szinek <p...@rubyrailways.com> wrote: > Just to make sure I am not reinventing the wheel(...

inputdlg in multi-column mode?
Hi, I use inputdlg as edit table for 10-20 variables (number and the names might change). Inputdlg puts all the edit boxes in one long column. Is there a way to place them in multi-column? If not do you know something in FEX that I can use to edit large number of parameters? Bruno ...

BIND with RPZ
This is a multipart message in MIME format. ------=_NextPart_000_00C7_01CEA5A8.B30F3490 Content-Type: multipart/alternative; boundary="----=_NextPart_001_00C8_01CEA5A8.B30F3490" ------=_NextPart_001_00C8_01CEA5A8.B30F3490 Content-Type: text/plain; charset="gb2312" Content-Transfer-Encoding: quoted-printable All, =20 Recently we put live some DNS Servers,=20 =20 The spec:=20 2x Xeon (total seen by OS 24CPU) 16GB RAM Ubuntu Server 12.04 =20 We test limited number RPZ list BIND 9.8.1 (came with Ubuntu 12.04), and = put it on the liv...

Looking for Motherboard/cpu/ram recommendations
Hi All, I have a QDI motherboard with a AMD xp 2400 166fsb with 1.5GB of pc2700 ram, and a 9800pro, it's adequate but with the new games on the horizon like Doom3 & HL2, I was thinking of upgrading the motherboard and cpu. (I'll be keeping the graphics card for a bit). Is there any particular Motherboard/CPU combination which works particularly well or anyone would recommend? Thanks in advance :-)) Jabout Asus and Athlon. Get a Athlon64 3200+ on a MSI Neo Platinum 250gb Socket754 board, a gig of PC4000 ram (to allow additional overclocking), and a Radeon X800pro. Also co...

Pass-through query as rowsource for combo box
Is it possible to set (using VBA) the rowsource for a combo box but have that rowsource come from a pass-through query. I can obviously manually go into the rowsource property and define the query and even set up the odbc string, but if i want to set this using VBA i cannot see how to do this. I know i can set forms!frm_test!combobox.rowsource to the SQL but that does not allow me to set the odbc for the passthrough element. Is it just not possible? Any thoughts woudl be gratefully received. Thanks. OK, i've discovered that i should be setting the RecordSet property as I can define ...

how to find available memory in linux box
I have a problem that is used to test memory leak as follows, however, after each run of the program, if I am using the command "free" on the linux box, I did not see any difference about the usable memory. My questions are: 1) How to find out exact free memory that my program can use? 2) Use which command to do this (top, or free) 3) why it does not show memory leak in my case (I am using the linux command free) ---------------------------------------------------------------------------------------------------------------- #include <iostream> #include <new> #include &...

two kinds of average filtering; exponential average VS modified moving average
1. exponential average. (some kind of one order IIR filter) according to RC filtering and moving average. ,we can get the exponential average equ: yk=fs/(fs+2*pi*1.5*fc)*y(k-1)+(2*pi*1.5*fc/(fs+2*pi*1.5*fc))*xk ---yk, the current output ---fs, sampling frequency ---fc, the low pass filter (RC filter) cutoff frequency 1.5*fc to make it in the passband for pratical caclulation. advantage: easy to be implemtated and need few RAM Disadvantage: can not smooth the abrupt noise that its frequency is more then fs/2. 2. modified moving average (some kind of modified FIR filter) when we get 4...

average and reset
Hello there, I have there sensors A,B and C which are used to measure the analog voltages. I want to run the DAQ for 5 minutes so that i can individually record the values for sensor A,B and C in three excel sheets. At the end of 5 min I want to calculate the average of values and will call themA(high), B(high), C(high). &nbsp; Then change one of the parameters in my experiment and redo the above process, that is run the&nbsp;VI for 5 min&nbsp; , put the values in three separate excel sheets. 5 min I want to calculate the average of values and will call themA(low), B(low), C(low). ...

Notebook CPU
Hi all I have a P4 2.4Ghz CPU from a Toshiba A70 notebook. I was thinking of using it in either a new desktop or replacing the cpu on my Toshiba 2410 notebook. question is 1. would I be able to use the cpu on a normal desktop motherboard and if yes I would there be any performance penalties or any other problems that might arise from using the CPU. 2. I currently have a Toshiba 2410 with a P4 1.7Ghz processor. Would it be possible to change this to the 2.4Ghz if so what probz would I expect (heating , compatibilities etc) and possible remedies??? Aerostar <aerostarsAT@gmaildot.com...

binascii.unhexlify ... not clear about usage, and output
Hi, I have a file with a long list of hex characters, and I want to get a file with corresponding binary characters here's what I did: >>> import binascii >>> f1 = 'c:\\temp\\allhex.txt' >>> f2 = 'c:\\temp\\allbin.txt' >>> sf = open(f1, 'rU') >>> df = open(f2, 'w') >>> slines = sf.readlines() >>> for line in slines: .... x = line.rstrip('\n') .... y = binascii.unhexlify(x) .... df.write(y) .... >>> df.close() >>> sf.close() But what I get is all garbage, atleast text...

vixie crond at 100% cpu, alternatives?
Hi all, Occasionally we are getting crond stuck on centos 5, as shown below via top: PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 23546 root 25 0 129m 2788 2048 R 100 0.1 248:48.72 crond Its process id zombied by getting set to 1: /root> ps -ef | grep 4776 root 4776 1 0 Apr06 ? 00:00:00 crond root 23546 4776 99 03:00 ? 04:09:13 crond The task that crond was asked to run is something that typically completes in less than 1 second, with very little load. We are running this version of crond: /etc/init.d> yum whatprovides ...

averaging a signal
hi all I have a signal from 2 accelerometers with impact tests being recorded. i want to split the signal into ech impact and average them, I know it sound so simple but im getting myself confused as top what to do with the script i have, which plots the nfft of the signal. this is my origional script where i just split the signal up into one peak: % Script for Copper rooms data= importdata ('imc1.txt'); % Extact time vector t=data (:,1); % Extract data from accelerometers a1=data (:,2); % accelerometer one a2=data (:,3); % accelerometer ...

CPU re-write mode MC16
Hi I am using IAR embedded work bench and trying to program(remotly) MC16, Mitsubishi) in CPU re-write mode. In CPU re-write mode, MC16 has only 20K available RAM but the OS is about 100K so I can not re-program the MC16 by copying the entire image to RAM. I wanted to know if I can program MC16 by block by block. IN other words, can I put my code in specific memory block in this way, I can re-program the specific block I want instead of re-writing the entire OS, image Any help would be appreciated, thanks, check out the Renesas website / M16C Application Notes. There is an appnote about the ...