[Solved] need to get cpu usage with 1 request


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] need to get cpu usage with 1 request
# 1  
Old 08-29-2012
[Solved] need to get cpu usage with 1 request

Hello,

i`m creating an script that collect`s data from virtual machines about cpu usage and store that data into RRD.

so everything now works fine, but it takes long time if in machine is a lot of virtual`s.

so i want to make my script to collect information with 1 request. at this time i`m collecting data like this:

Code:
cpu=`vzctl exec $veid top -bn2 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%\id.*/\1/" | tail -n1 | \
awk '{print 100-$1}'`
wa=`vzctl exec $veid top -bn2 | grep "Cpu(s)" | awk '{print $6/1}' | tail -n1`

i use top -bn2 so it takes second line from top ( because the first line do not show proper value ) and if there is about 30 virtual machines to go all script around it takes some time, becose there are 2 requests: 1 for cpu ( us+sy+ni+hi+si+st ) and second to get wa

so if there is posible to get with 1 request those 2 variables then script would run twice faster

thanks for any advice and sorry for my bad english .

Last edited by vbe; 08-29-2012 at 11:14 AM.. Reason: typos...
# 2  
Old 08-29-2012
You know, it does help to mention your OS and version...
When we get old it takes time ( a lot of) to figure what it can be in order to understand what you are up to...
# 3  
Old 08-29-2012
Why you do tail -n1 after the sed and awk treatment (and not before) ? Is it possible to do this kind of thing ?
Code:
first_line=`vzctl exec $veid top -bn2 | grep "Cpu(s)" | tail -n1`
cpu=`echo "$first_line" | sed "s/.*, *\([0-9.]*\)%\id.*/\1/" | awk '{print 100-$1}'`
wa=`echo "$first_line" | awk '{print $6/1}'`

# 4  
Old 08-29-2012
delugeag thanx, hou i did`nt invet`ed that, thnx again
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

CPU Usage

Hi Experts, We encountered problem in one of the production system where some processes were taking higher CPU and after some time it came back to normal.. From system prespective, is there any way to check why processes took more cpu during that particular period. (16 Replies)
Discussion started by: sai_2507
16 Replies

2. AIX

How to monitor the IBM AIX server for I/O usage,memory usage,CPU usage,network..?

How to monitor the IBM AIX server for I/O usage, memory usage, CPU usage, network usage, storage usage? (3 Replies)
Discussion started by: laknar
3 Replies

3. Solaris

Multi CPU Solaris system shows 100% CPU usage.

Hello Friends, On one of my Solaris 10 box, CPU usage shows 100% using "sar", "vmstat". However, it has 4 CPUs and prstat and glance are not showing enough processes to justify high CPU utilization. ========================================================================= $ prstat -a ... (4 Replies)
Discussion started by: mahive
4 Replies

4. Solaris

current CPU usage, memory usage, disk I/O oid(snmp)

Hi, I want to monitor the current cpu usage, monitor usage , disk I/o and network utlization for solaris using SNMP. I want the oids for above tasks. can you please tell me that Thank you (2 Replies)
Discussion started by: S_venkatesh
2 Replies

5. HP-UX

how can I find cpu usage memory usage swap usage and logical volume usage

how can I find cpu usage memory usage swap usage and I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times my final destination is monitor process logical volume usage above X % and number of Logical voluage above can I not to... (3 Replies)
Discussion started by: alert0919
3 Replies

6. Programming

CPU usage and memory usage

Please tell me solaris functions/api for getting following information 1- Function that tells how much memory used by current process 2- Function that tells how much memory used by all running processes 3- Function that tells how much CPU is used by current process 4- Function that tells how... (1 Reply)
Discussion started by: mansoorulhaq
1 Replies

7. UNIX for Dummies Questions & Answers

cpu usage

when i got the cpu usage values of the all process running in my sytem i see that 140% of the cpu is used. (using ps aux command) i have a 4 cpu system. can we say that averagely 35% of each cpu is used? and if i want to speak more precisely, how can i find out that, which cpu is used at... (4 Replies)
Discussion started by: gfhgfnhhn
4 Replies

8. SuSE

Request:- Could some do a poll of Linux version usage?

I don't know nearly enough about what versions of Open/Free Linux are available. I was wondering if someone would create a new poll of all the major recent(ish) distros so we can see the percentage of people's preferred distro? I've only ever used Suse and have been very happy with it, but... (0 Replies)
Discussion started by: Mark Ward
0 Replies

9. Programming

Monitor CPU usage and Memory Usage

how can i monitor usages of CPU, Memory, Hard disk etc. under SUN Solaries through a c program or java program i want to store that data into database so i can show it graphically thanks in advance (2 Replies)
Discussion started by: Gajanad Bihani
2 Replies

10. Filesystems, Disks and Memory

cpu usage

hi, In response to your cpu usage answer I too read sys/sysinfo.h but , if we put these values to access the repective time fields in the array pst_cpu_time which is a member of the structure pst_dynamic values doesn't seem to match, why is like this? (0 Replies)
Discussion started by: sushaga
0 Replies
Login or Register to Ask a Question