Monitoring process CPU and Memory usage
Hi everyone,
I want to build a script that monitors CPU usage and memory of certain processes. I know which PIDs the processes have and the most important thing to me is the accuracy of the readings. I want to produce an overall graph of memory usage and cpu usage for each of my processes. Which is the best command/method to capture the data do you think? Thanks for any help, jT |
The ps command allows you to specify options as to which metrics you want as well as to specify which process to show with the -p flag. You can use the h flag to suppress print of the header.
So: Code:
while true; do ps h -p<pid> -o pid,ppid,user,group,%cpu,%mem,rss,sz,vsz,cmd ; sleep 5; done This is standard ps command but instead of using default "-ef" you specify the options you want with "-o". As noted the h suppresses the header. The options are separated by comma. The options shown above are: pid Process ID number ppid Parent process ID number user Effective user name (owner of the process) group Effective group name (group of the process) %cpu Percent of CPU utilization %mem Percent of memory utilization rss Resident Set Size sz Size in physical pages of the core image. vsz Virtual memory size cmd The command and its arguments. Putting it last in options gives full details. Putting it anywhere else in options gives an abbreviated output. You can of course use only the %cpu and %mem to get those two basic metrics you requested. You can also change the sleep to a number greater than 5 (seconds) depending on what measurement interval you wish. Do NOT eliminate the sleep entirely as it will kill your CPU. |
Hmm. I'd try searching Freshmeat and Sourceforge for a monitoring application before giving in and writing a script. Chances are this particular wheel was already invented, maintained and supported.
|
Problem is, I'm very limited on what is installed on these machines. Scripting is the only way to do it.
I've figured out what I need to do but I'm stuck at a another hurdle now, see my other post http://www.linuxquestions.org/questi...aiting-639291/ |
If you "figured out" what you needed to do and it wasn't in one of the posts above you should post your solution so others searching the forum for similar question will find it and not have to ask.
|
So what I need to do was to remotely kick off a process and then monitor its memory and cpu usage.
So on my local machine the pseudocode would be as follows:- Code:
RPID = rsh host mycommand& |
All times are GMT -5. The time now is 12:06 AM. |