Reputation: 21
I am looking to log the CPU, Memory, Bandwidth for a process running on Linux. Ultimately the data will be stored in a database, but my main question is how to get access to this data to log in the first place.
My initial thought is to use the top command, and parse the data I need.
Can you think of a better way?
Upvotes: 2
Views: 2402
Reputation: 122458
Check out the /proc
pseudo filesystem—you can read the files in there from scripts, compiled programs, anywhere.
I have already implemented a similar system and used 'sar' extensively, parsing the output using 'awk', however 'perl', 'python', or any such would work just as well. I made each of these scripts output CSV and then bulk-loaded the CSVs into MySQL for later querying/charting via PHP.
Upvotes: 2
Reputation: 9942
The kernel can be configured to do this with "process accounting". A web search for that and "linux" will find a wealth of information on how to set it up.
Upvotes: 0
Reputation: 7790
You may use ps for CPU and Memory, something like:
ps -eo pid,user,args,%mem,%cpu
and then parse output.
Upvotes: 1