LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 10-19-2011, 03:03 AM   #1
MaRiOsGR
LQ Newbie
 
Registered: Oct 2011
Posts: 8

Rep: Reputation: Disabled
Looking for a script/program/util that can give me stats of CPU usage for a user


Hello,

I'm looking to find a way to get CPU usage stats with percentage for a single user in a linux server.

I do not want a monitoring script, just to setup the script/util to watch a username and give me every 24 hours a percentage of CPU usage.

thank you.
 
Old 10-19-2011, 03:32 AM   #2
utsuprainfra
LQ Newbie
 
Registered: May 2011
Location: Philadelphia
Distribution: Ubuntu, Slackware, ?
Posts: 4

Rep: Reputation: 0
so

top -b -n 1 -u username | awk 'NR>7 { sum += $9; } END { print sum; }'

maybe with a cron?

or, from the same link you probably saw:

munin-monitoring org?
 
Old 10-19-2011, 06:25 AM   #3
MaRiOsGR
LQ Newbie
 
Registered: Oct 2011
Posts: 8

Original Poster
Rep: Reputation: Disabled
utsuprainfra thank you very much for the reply.

top -b -n 1 -u username | awk 'NR>7 { sum += $9; } END { print sum; }'
gives me the load in the exact moment that I run the command,
how can I make it monitor the user and give me the average on 24 hours?
 
Old 10-20-2011, 01:10 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,356

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
You simply run that as often as you think reqd eg every hour and save the results, then calc avg after 24 hrs.
 
1 members found this post helpful.
Old 10-20-2011, 07:15 AM   #5
utsuprainfra
LQ Newbie
 
Registered: May 2011
Location: Philadelphia
Distribution: Ubuntu, Slackware, ?
Posts: 4

Rep: Reputation: 0
chrism01 makes a good suggestion. run it every 10 seconds if you want.

*though top used to suck resources, unsure if it is significant enough draw to throw results in "modernity" (today).

Last edited by utsuprainfra; 10-20-2011 at 07:18 AM.
 
Old 10-20-2011, 07:17 AM   #6
MaRiOsGR
LQ Newbie
 
Registered: Oct 2011
Posts: 8

Original Poster
Rep: Reputation: Disabled
thats a good idea.
is there any automatic way to calculate the average? (that I could add it in the script?)
 
Old 10-20-2011, 07:42 AM   #7
utsuprainfra
LQ Newbie
 
Registered: May 2011
Location: Philadelphia
Distribution: Ubuntu, Slackware, ?
Posts: 4

Rep: Reputation: 0
give me 3 instances of output. i'm on a windows machine right now and can't boot into linux...
 
Old 10-20-2011, 08:11 AM   #8
MaRiOsGR
LQ Newbie
 
Registered: Oct 2011
Posts: 8

Original Poster
Rep: Reputation: Disabled
[root@ /]# top -b -n 1 -u e*******p | awk 'NR>7 { sum += $9; } END { print sum; }'
128.5
[root@ /]# top -b -n 1 -u e*******p | awk 'NR>7 { sum += $9; } END { print sum; }'
149.3
[root@ /]# top -b -n 1 -u e*******p | awk 'NR>7 { sum += $9; } END { print sum; }'
87.5
 
Old 10-20-2011, 11:24 AM   #9
MaRiOsGR
LQ Newbie
 
Registered: Oct 2011
Posts: 8

Original Poster
Rep: Reputation: Disabled
ok I got it, I just send the result to a text file top -b -n 1 -u username | awk 'NR>7 { sum += $9; } END { print sum; }' ? test.txt

and then run awk '{ total += $1; count++ } END { print total/count }' test.txt
 
Old 10-20-2011, 11:43 AM   #10
MaRiOsGR
LQ Newbie
 
Registered: Oct 2011
Posts: 8

Original Poster
Rep: Reputation: Disabled
but now a new question came up...
top -b -n 1 -u username | awk 'NR>7 { sum += $9; } END { print sum; }' >> test.txt

works fine but in some occassions the cpu usage is 0
so the content of the file is like:

0
25
0
0
85

etc etc , can can I make it NOT count the zeros ? for example run the command top -b -n 1 -u username | awk 'NR>7 { sum += $9; } END { print sum; }' and if the result is 0 then not run >> test.txt , if it is any other number then procced to >> test.txt
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Script to give the disk usage in GB for each user. Tekken Linux - Server 2 09-08-2009 07:00 AM
Not a single program for logging daily cpu usage? centosfan Linux - Server 2 06-28-2009 08:00 AM
ram/cpu usage etc... program Ken~ Linux - Software 2 08-28-2007 05:38 PM
How to get CPU usage in a script -kolja Linux - Software 6 12-26-2006 08:41 PM
how to determine cpu usage, memory usage, I/O usage by a particular user logged on li rags2k Programming 4 08-21-2004 04:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 07:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration