#1  
Old 23rd July 2008, 23:48
martien martien is offline
Junior Member
 
Join Date: Oct 2007
Posts: 26
Thanks: 2
Thanked 2 Times in 2 Posts
Default getting cpu usage per user

Hello everyone. I need a script or the way to make script for getting the cpu usage per system user. I want when I type the script name and the user name (as parameter) to have the current cpu usage. It can be an already done application in whatever language - php,perl,c,bash or just the way to write one. I have few users on my server and they have their own sites and i want to know if they are too hard. Thanks in advance

Last edited by martien; 23rd July 2008 at 23:50.
Reply With Quote
Sponsored Links
  #2  
Old 24th July 2008, 09:42
burschik burschik is offline
Junior Member
 
Join Date: May 2008
Posts: 24
Thanks: 0
Thanked 2 Times in 2 Posts
Default

A simple solution would be

top -b -n 1 -u username | awk 'NR>7 { sum += $9; } END { print sum; }'
Reply With Quote
The Following User Says Thank You to burschik For This Useful Post:
martien (24th July 2008)
  #3  
Old 24th July 2008, 11:43
martien martien is offline
Junior Member
 
Join Date: Oct 2007
Posts: 26
Thanks: 2
Thanked 2 Times in 2 Posts
Default

Quote:
Originally Posted by burschik View Post
A simple solution would be

top -b -n 1 -u username | awk 'NR>7 { sum += $9; } END { print sum; }'
That's exactly what i'm looking for. But I have а little lack of understanding - can you explane me this part:
Code:
awk 'NR>7 { sum += $9; } END { print sum; }'
10x in advance again.
Reply With Quote
  #4  
Old 24th July 2008, 13:10
burschik burschik is offline
Junior Member
 
Join Date: May 2008
Posts: 24
Thanks: 0
Thanked 2 Times in 2 Posts
Default

AWK is what you might call a pattern processing language. It splits its input into records (delimited by newlines by default), compares each record to a number of patterns and takes appropriate actions if it matches. Each record is further split into fields (delimited by white space by default), which are assigned to the variables $1 to $NF (NF is the number of fields).

In our example, we use two patterns, namely "NR>7" and "END". NR is the number of records, a pre-defined variable. BEGIN and END are special patterns that match the beginning and the end of the input. So, what the small AWK program does is this: If the record number is larger than 7, increment the variable sum by the value of field 9 (the percentage of CPU cycles used). After all records have been processed, print out the value of sum.
Reply With Quote
The Following User Says Thank You to burschik For This Useful Post:
martien (16th August 2008)
  #5  
Old 16th August 2008, 20:45
martien martien is offline
Junior Member
 
Join Date: Oct 2007
Posts: 26
Thanks: 2
Thanked 2 Times in 2 Posts
Default

Thank you @burschik. You were very helpful fo me.
Reply With Quote
  #6  
Old 27th August 2008, 10:56
gracie20 gracie20 is offline
Junior Member
 
Join Date: Aug 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Smile

Thanks a lot for the information. It will help me alot.

Gracie Sh
http://hdtvlcdplasma.com
Reply With Quote
  #7  
Old 1st April 2009, 01:12
make-fun make-fun is offline
Member
 
Join Date: Jan 2008
Posts: 92
Thanks: 8
Thanked 8 Times in 7 Posts
 
Default

A bit of a late reply…

Anyway, a more comfortable way would be using Munin and a plugin from MuninExchange called "cpubyuser".

http://munin.projects.linpro.no/
Plugin CpuByUser

Works like a charm and gives you a much better picture;-)

Cheers
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Statistic not working mzo Installation/Configuration 49 20th April 2011 12:19
Anything I can do against illegal login-requests? schmidtedv Installation/Configuration 17 7th November 2008 09:25
Squid Proxy Caching on Linux obzerver Installation/Configuration 4 13th August 2008 19:51
Ruby / FastCGI Problem Chad Server Operation 1 8th March 2008 20:38
log files cruz Technical 3 15th May 2007 14:35


All times are GMT +2. The time now is 06:59.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.