2

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?

1
  • 1
    Google up "process accounting" Commented Jan 5, 2011 at 18:46

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I'd also recommend checking out the source to top itself, which uses the proc fs under the covers. It's available at http://procps.sourceforge.net
1

You may use ps for CPU and Memory, something like:

ps -eo pid,user,args,%mem,%cpu

and then parse output.

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.