How to monitor the following metrics for a process in linux? I am using suse linux enterprise 11 SP1 64 bit.
- %CPU time
- Handle Count
- Private Bytes
- thread Count
Is these any tool available for linux for this purpose?
How to monitor the following metrics for a process in linux? I am using suse linux enterprise 11 SP1 64 bit.
Is these any tool available for linux for this purpose?
1.For handle count or the number of file handles you can use the lsof command as:
lsof -p (process id)
For more information see this link.
2.For thread count use:
ps uH p <PID_OF_U_PROCESS> | wc -l
Here it also counts the header, so (output-1) is what you are looking for.
3.For CPU time , memeory etc you can use "top". It gives the CPU usage, memory usage, etc for every process. 4. I am not sure what you mean by private bytes sorry.
For monitoring these metrics on linus you could use some tools like SeaLion, Munin, etc which are meant for this purpose. If you are using for a simple purpose, SeaLion seems ideal. It is very easy to setup on multiple servers and is free.
perhaps:
ps --no-headers -p $pid -o "pcpu,nlwp"
grep Private /proc/$pid/smaps | awk '{ sum += $2 } END { print sum }'
ls /proc/$pid/fd | wc -l
the ps gives you a point in time cpu usage and thread count the grep gives you a sum of private memory in kilobytes (*1024 to get bytes) and the ls gives you the number of file handles open.
ps has other options to give you memory info. It won't give you specifically private memory usage, but perhaps rss, size, or vsz would work for you.
In case you want the raw data, the following answer on StackOverflow answers your question: How to calculate the CPU usage of a process by PID in Linux from C? /proc/[pid]/stat lists some useful information about a linux process.
If you just want to check the average CPU time for a process, you can use the ps (see the manpage!) or something like: ps -eo "%p %y %x %C %c" --sort c
Also a useful tool is top ... just type 'top' in the command line and you'll get information about CPU, memory, ...
Try the manpages or google for more information about top and ps