unix

OpenBSD Administration Training: Collecting Load Averages with Uptime(1)

uptime(1) is handy to get a quick snapshot of some basic system information and often that’s all you need to decide what to do next, but if you want to get a better view of the load average patterns on your system, you will need to run uptime(1) at regular intervals over a period of a day, or week. Here’s a script that runs uptime(1) at 15-minute intervals for 24 hours. We'll call it uptime-mon.sh.


loopon=1;

loopdelay=900;

loopend=96;

n=0;

while [[ $loopon -eq 1 ]]; do

        if [[ $n -eq $loopend ]]; then

                exit

        fi

        sleep $loopdelay

        uptime

        n=$n+1

done

If you wonder where I got those numbers from, you should know that the ksh(1) sleep command expects that we express the delay in seconds therefore 15 minues translates into 15*60 = 900. And since each hour is made of four 15-minute segments, we have to run uptime(1) 4*24 = 96 times.

Remember that the script shown above will stop as soon as you close the terminal window or log out of the system, so make sure it runs in the background and does not stop after you log out of the system:


$ nohup uptime-mon.sh > 24-hr-uptime &

When you log in the next day, you will be able to monitor the results as the are being written with this command:


$ cat 24-hr-uptime | less

If you have better things to do than babysit uptime(1), you can make your script deliver the results straight to your mailbox when it's done:


$ nohup uptime-mon.sh | mail joe &

The above is a fragment of a longer article to be published next Monday. Subscribe to our Articles list to get the whole thing.

vi Tips - 001 PANIC in high quality

As you have no doubt noticed, the quality of our videos on YouTube leaves a lot to be desired. Here's a blip.tv version. Much better, imho.

devGuide.net Training News Mailing List