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 |
|
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
|
|
|
3 Replies
324 Views
(page loaded in 0.95 seconds)
Similiar Articles: Mysterious CPU consumption - comp.unix.programmer... 30% user and 70% system, and the load average is just ... This is indeed a multi-threaded application. Cheers ... least > > a factor of 10 and the Solaris system CPU usage ... convert CPU load to CPU utilization in % - comp.unix.solaris ...Hi, Is it possible to convert the cpu load average (5min) got from the ... How can I ... dcom.sys.cisco On a good day, high CPU (central processing unit) usage will ... how to generate 100% cpu load on solaris 10 zone - comp.unix ...... most at 33% I am not sure on what exact solaris box ... pegs a single CPU at 100%, however for a multi-CPU ... Capping CPU usage in zones. - comp.unix.solaris CPU core ... prstat -a vs. vmstat - comp.unix.solarisThe box has 12G of memory. vmstat 1 2 procs memory page disk faults cpu r b w swap free re ... each time a page is counted multiple ... Controlling CPU utilization of a process - comp.unix.solaris ...... is trying to give a upper limit for cpu usage of ... under- or over-represented in the load average numbers. CPU ... process - comp.unix ... computer's central processing unit can ... CPU info - comp.unix.solaris... CPUs (this is on a dual CPU box with ... processors - comp ... Each processor incorporates eight cores, and can be used in multi ... Get CPU usage and temperature - comp.os ... Sending UDP packets at a specified rate - comp.unix.programmer ...But I would hog the CPU even though I only need 2-3% of it on average... ... 4) Is the bandwidth usage low and ... If one has a multiple CPU system, or even multiple ... newbie question: shell script to monitor server performance - comp ...... which captures: 1) CPU, disk, memory, swap usages, i/o stats. I need the information to be simple and dispalyed like the disk usage and ... It's portable across multiple ... Which CPU or core to disable? - comp.unix.solaris... power-cycle before it came back to normal. A ... eHow.com Dual-core processors are a CPU (Central Processing Unit ... may be necessary to disable a core in a multi-core CPU. Fujitsu Siemens Primepower - comp.unix.solarisIf the expected load average is < 2-3 then the PP250 ... The only difference in register usage between v8plus ... Machine type: RISC-based shared-memory multi-processor. Re: Average CPU Usage for multi CPU box. - Der Keiler UNIX: The ...On May 8, 10:51 am, dave.cla...@xxxxxxxxxxxxxx wrote: On 8 May, 09:38, gerryt <lepsys...@xxxxxxxxx> wrote: On May 8, 8:41 am, dave.cla...@xxxxxxxxxxxxxx wrote: Understanding Linux CPU Load - when should you be worried?On multi-processor system, the load is ... On a dual-core box, a load of 2.00 is 100% CPU utilization. ... that could drive your load average up to 1.0, even though your CPU ... 7/24/2012 4:59:07 AM
|