Solved

script to check server load

Posted on 2011-09-17
2
451 Views
Last Modified: 2013-12-16
hello there,
I would like to know how can I create a little tool that can check server load every minute and if the server loads is more than 10
then I would like to rename a dir.. how can I do that on centos v5.6?
0
Comment
Question by:XK8ER
2 Comments
 
LVL 77

Expert Comment

by:arnold
ID: 36554789
you can use cron to run script to check topm -n 1, uptime, and then use the information to do what is the effect of renaming a directory?
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 36554792
Hi,

I assume that you're talking about the 1-minute average load as displayed by "uptime"?

If so, you could run this script in background which would check every minute and  sleep inbetween:


#!/bin/sh
while :
  do
   if [[ $(uptime | awk '{print int($10)}') -gt 10 ]]; then
    echo Load greater 10, renaming ...
    echo mv olddir newdir
    exit
   fi
   sleep 60
  done

Please note that the script exits once a load of 10 has been reached,
to avoid running the now useless mv command over and over.

Note further that I put echo in fron of the mv statement, to allow testing.
Remove it when you're satified with the outcome.

Run this script like this:

nohup /path/to/script >/path/to/log 2>&1 &

An alternative could be running a modified version (without "while" and "sleep") of the script every minute via cron.
Should you like this idea we must take care, however, to avoid useless executions!

wmp
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is the error message I got (CODE) Error caused by incompatible libmp3lame 3.98-2 with ffmpeg I've googled this error message and found out sometimes it attaches this note "can be treated with downgrade libmp3lame to version 3.97 or 3.98" …
Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question