How to measure CPU/Memory usage?

Posted on 2008-10-07
Last Modified: 2013-12-26

I'm working on a project that one of its tasks is to measure the average memory and cpu usage for the passed X minutes. The plan is to cover tier 1 Unix/Linux OS,

I'm a programmer and not very familiar with the different technical aspects of cpu and memory but I do know that these is no single number that represents them.
I found out in Unix the command "vmstat" that gives information about memory, cpu, page fault and other system parameters but I'm not sure this is the right tool. I mean, there is user cpu usage and system cpu usage. How do you figure out a single number that represents the overall cpu usage? The same goes for memory, there is phisical memory, and virtual memory and some other memory related parameters.
And what happen if you have 16 cpus? Can you boil it down to a single number?

The design is that a user will define a minimum free cpu usage and a minimum available memory, and if these conditions are met, only then other tasks will be performed. This is to prevent a situation in which a task is submitted to a machine that is already overloaded.

How would you approach such a task?
Do you know of any 3rd parties softwares or utilities that yield such information?

Question by:nivo_Z
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
LVL 45

Expert Comment

ID: 22657456
Use top command for real time monitoring ... top -b gives you periodic snapshots ... man top for more info
Also look into time command to time the execution of your program ... and of course there are profilers for memory and CPU e.g. memprof, valgind, gprof etc.

Author Comment

ID: 22657908
Thanks fpr your reply.
Top is not necessarily installed, the solution should be generic and sould use tools that exist by default.
LVL 45

Expert Comment

ID: 22657941
what all tools are available?
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Accepted Solution

tjilp earned 55 total points
ID: 22658009
How about something simple like "ps".
ps has an option  that allows you to format it's output.
online man page example :
or better try : man ps

for instance "ps -eo pid,pcpu,comm,args" gives you the pid , the processor usage, process name and it´s arguments

LVL 62

Expert Comment

ID: 22695344
SNMP agent is existent on all platforms. read host mib.

Assisted Solution

deloptes earned 80 total points
ID: 23212029
how to mesure the memory usage of a perl script?

this can not be caught with top, ps and /usr/bin/time -v prints everywhere a 0.

time prints
real    0m0.608s
user    0m0.523s
sys     0m0.033s

/usr/bin/time -v
        Command being timed: "perl"
        User time (seconds): 0.51
        System time (seconds): 0.03
        Percent of CPU this job got: 81%
        Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.66
        Average shared text size (kbytes): 0
        Average unshared data size (kbytes): 0
        Average stack size (kbytes): 0
        Average total size (kbytes): 0
        Maximum resident set size (kbytes): 0
        Average resident set size (kbytes): 0
        Major (requiring I/O) page faults: 0
        Minor (reclaiming a frame) page faults: 3764
        Voluntary context switches: 147
        Involuntary context switches: 180
        Swaps: 0
        File system inputs: 0
        File system outputs: 0
        Socket messages sent: 0
        Socket messages received: 0
        Signals delivered: 0
        Page size (bytes): 4096
        Exit status: 0

LVL 62

Assisted Solution

gheist earned 40 total points
ID: 23212123
You should use process accounting. most likely psacct package contains sa, sar and accton tools and google will show you enough guidance for your purpose.

Assisted Solution

deloptes earned 80 total points
ID: 23216229
Hello, thank zou for the answer. I was googleing for about an hour but couldnät find anzthing usable, also non of the mentioned programs has ever appeared upto page #5 in google :-) so I sould try something you've mentioned google about it and read the man page

thanks and regards

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question