Solved

script to check server load

Posted on 2011-09-17
2
455 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 78

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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.

738 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