Linux ps
How to keep track of how heavily a process is loading the cpu on a server.
Resources
Workflow
- set up bash file to run ps and append data into file ~/monitor.process
#!/bin/bash
# filename monitor.process
# run ps, append to monitorLogfile
ps -f -U mysql -u mysql --no-headers >> mysql.monitor
- Modify to add datetime stamp
#!/bin/bash
# monitorlogfile mysql.monitor
# run ps, filter, append with datestamp to monitorLogfile
DATESTAMP=`date +%y%m%d-%H%M%S`
MONITOR=`ps -f -U mysql -u mysql --no-headers`
echo $DATESTAMP $MONITOR >> mysql.monitor
- Make file executable
$ chmod 744 ~/monitor.process
$
- Set up cron to run this at set interval
# use 'crontab -e' to add to your crontab
$ crontab -e
# new crontab entry:
# run monitor.process 4 times per hour
*/15 * * * * /home/ubuntu/monitor.process
- Do something with log file, e.g.,
- Alert if getting too large
- Roll log file periodically, e.g.,
- Use cron to once a week rename log to dated log file (like mysql.monitor.210323).
- Next cron run will create a new log file.
- make sure not to run on 0,15,30,45 minute which could conflict with the 4 time per hour routing, above.