简体   繁体   中英

Monitoring system performance in Linux server with the top command

I'm trying to pull in system performance information ( PID, User, CPU, MEM and Time) into an excel file. I will be doing this via a shell script. I tried the top command. It has all the information, however it has all the child process information as well. Is there a way to aggregate all the child processes with the parent process so that I can look at one process and say it took so long to complete. Also, is there a way to display and pull PPID information with the top command?. If there are other ways to do this, I would be open to that as well. I want to aggregate all the child processes with the parent processes and look at system performance for different users. This is the code that I tried in a shell script.

top -n1 -b \
|awk '{if (($1 ~ /^[0-9]/) || ($0 ~ /PID/ )) { 
  print $1","$2","$4","$5","$6","$7","$8","$9","$10","$11","$12","$13","$14","$15; } 
 }' > file.csv

I am using red hat linux. Help will be appreciated.

You should be able to achieve what you are asking by directly reading from /proc. This is essentially how top, free etc. get their data.
See eg http://www.centos.org/docs/5/html/Deployment_Guide-en-US/ch-proc.html or man proc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM