3

I need to monitor the CPU and Memory usage for a single process in an AIX server. The program runs 3 times a day. I need to find the way to capture statistics within some time intervals, lets say every 10 min.

1

I suggest collecting overall system statistics with nmon and parsing them with nmon-analyzer or nmon2rrd - even if it's just for one process. Having something to correlate with is useful. svmon can also be used to monitor memory usage.

Here are some good articles on process and system monitoring for AIX:

0

I assume aix works like gnu/linux. Create a file in /etc/cron.d/. Let's call it 'monitor' change the grep processname part to your processname

# +---------------- minute (0 - 59)
# |  +------------- hour (0 - 23)
# |  |  +---------- day of month (1 - 31)
# |  |  |  +------- month (1 - 12)
# |  |  |  |  +---- day of week (0 - 6) (Sunday=0 or 7)
# |  |  |  |  |
# *  *  *  *  *  user    command to be executed
*/10 *  *  *  *  root    ps aux | grep processname >>/var/log/mylog.log

add the following line to /var/log/mylog.log

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND

if you don't have root, you can start crontab -e as user omit the username root before ps aux, and instead of redirecting the output to /var/log/ you should use $HOME/.

0

I am just giving an idea and not a complete script. You need to modify to suit your requirements.

To monitor the CPU usage and memory usage, the command that you use is ps. I believe -C and -o flags are supportedin AIX server. Nevertheless, you could figure out the corresponding syntax from man ps in your machine.

ps -C program_name -o %cpu,%mem

Now, to make it execute every 10 minutes for 6 times in the server, I would put the below script. I assume you need to monitor once in every 10 minutes for an hour or so.

i=6
filename=$(echo memory_monitoring_`date +%F_%T`)
touch $filename
while [ $i -ge 1 ]
do
    sleep 600 #sleep for 10 minutes. 
    ps -C program_name -o %cpu,%mem >> "$filename"
    i=$((i-1)) 
done

So basically with the above script, I create a new file every time I need to monitor the memory. After that, I execute the script for 1 hour which is why you see i is set to 6. sleep 600 is for monitoring the memory every 10 minutes.

If you need optimizations, you could add a mail command to email yourself the created file so that you could use it for auditing purposes.

Setting up a cron job is fairly straight forward and you could find numerous online tutorials that could help you out.

  • Ramesh, '-C' flag did not work, so I used $ps -ef | grep 'process_name'. It returned three different PIDs for the same processes. I do not know which id corresponds to which process. How would I find unique PID I need? – ellen Nov 12 '14 at 23:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.