Monitor average CPU usage and RAM usage on one process linux
Solution 1
read man 5 proc
, especially the /proc/[pid]/stat
entry and the utime
, stime
fields. /proc/[pid]/status
or /proc/[pid]/statm
might be of interest for you as well.
then use cron
or whatever means needed to collect 'snapshots' of /proc/[pid]/stat
for your process over a period of time. then visualize what you have grabbed.
a simple 'collector' works like this (for a process with the pid '29777'):
% while true; do cat /proc/29777/stat; sleep 1; done
to make life easier, you could also use the systat package which includes several means to collect data over time:
http://sebastien.godard.pagesperso-orange.fr/documentation.html
Solution 2
pidstat is a very good tool for the cpu part of your question.
http://xmodulo.com/2012/08/how-to-measure-average-cpu-utilization.html
Related videos on Youtube
Pez Cuckow
Updated on September 17, 2022Comments
-
Pez Cuckow over 1 year
Is there any way to monitor one process' CPU usage and RAM usage over time on linux? I am trying to change to a cheaper VPS and need to work out what level of CPU and RAM I need!
-
Ryan C. Thompson over 13 yearsShouldn't you be more interested in maximum memory usage?
-
-
Ryan C. Thompson over 13 yearsTop only provides instantaneous snapshots of CPU and memory usage. The OP asks how to collect aggregate statistics over time.
-
Pez Cuckow over 13 yearsSounds an interesting idea, i'll give it a go and update you with the result.