5

I am looking for a script which does monitor the cpu usage per day. All the scripts that I have come across does kind of real time monitoring and send an email if it meets certain aspects like the load increasing beyond 80%.

Is it possible to monitor and understand the Maximum, minimum and average utilization of a CPU using a shell script?

3 Answers 3

4

You can use below script to monitor server load,

#!/bin/bash
r=$(cat /proc/loadavg | awk -F. '{print $1}')
if [ $r -ge 50 ]
then
/bin/mail -s "Warning: High Server Load on: `hostname -i` Load Average: $r"     [email protected]
fi

save it as, loadmon.sh

add cron:

 * * * * * /bin/sh /path/for/loadmon.sh

Thanks.

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

1 Comment

To get load average in "percent" (that is, integer), you can just use: awk '{print $1 * 100}' /proc/loadavg. If this is not smaller than 100*number of CPUs, the server is under heavy load.
1

It's been more than one year to this question and this is how I fixed it at the time. I apologize for the delay in posting as I am not a frequent user.

I have written a script using vmstat and wrote the output to the fileload.log on a daily basis. I then took it to internet and there is an excellent load monitoring tool that converts the vmstat log to graphs of CPU, RAM and processor utlis. I have used this free tool to visualize the vmstat graphs.

vmstat -n 5 > vmstat.log

Check VMStax for Visualization of vmstat for uploading the vmstat log to generate the graphs.

Thanks!

Comments

0

i think you don't need a script for this task. you can use mpstat or sar follow the link for detail description: http://www.linuxexplorers.com/2012/08/linux-commands-to-check-cpu-and-memory-usage/

3 Comments

Thans fecub. But both of them do not accomplish what I want. Because I do not have the options -p -r in the RHEL edition of linux I am using. Weird, but can't help. Is there any other way?
I am trying to use ksar to see if that helps me. Will post the results back.
Finally found out that the sar that's in my system is so old that it can give me data only of last september. So whatever I do, I am again at square 1. Now trying to see if vmstat helps me. Thanks

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.