Load average monitor script for FreeBSD servers with mailing option.

Recently I had problems with two of the servers I support because of DDoS attacks in the datacenter. Then I needed some load average reports for these servers, a script to inform me or directly to stop the network service if heavy pressure is taken.
Previously I haven’t needed load average script since the servers are just storages and those I have used were either for Fedora or Debian servers.

I decided not to ‘invent the hot water’ and went through the Internet to find solution.
Certainly the first search engine result for ‘Load average monitor script BSD server‘was at FreeBSD forums .

Unfortunately that script was not working with just copy and paste and I spend some time to graze it for my servers. The final version became this:

The crash point (i.e. the main difference between the FreeBSD’s load average script from http://forums.freebsd.org and the above listed) was the part where the condition is set.

What I mean?
In the initial script the condition is: ‘if [ "$MLAVG" -ge "$MAX_LAVG" ]; ‘ , but for some reason it was not working fine. Finally I concluded the load average FreeBSD script with this solution: ‘if [ $(echo "$max_loadavge < $loadavg"|bc) -eq 1 ];’ . It is pretty the same, but it works.

For sure my monitoring load average script is working on FreeBSD 6.* and FreeBSD 7.* I see no reasons have issues working on the newer versions.

An elegant decision will be if ‘while’ operator is used, and the script is running constantly, but I decided to have it in my ‘crontab’ for easier time management.

When the script is executed it will check the current load average status and if it is bigger than the one set under ‘max_loadavge’ will generate the next listing and will e-mail it to ‘EMAIL1’.

If you are experienced user you may notice this line inside script the which is commented:

This will always enter the current server’s load average value inside ‘load.log’ , but I am running this script every 30 seconds, and I have to do log-rotate as well, so I am turning that on only in case I need it.

Hope this article was useful for you and will help you to monitor load average on FreeBSD server of yours.

Filed Under: Monitoring

Anthony Gee About the Author: Anthony G. is an IT specialist with more than 9 years of solid working experience in the Web Hosting industry. Currently works as server support administrator, involved in consultative discussions about Web Hosting and server administration. One of the first writers in the Onlinehowto.net website, now writing for Free Tutorials community - he is publishing tutorials and articles for the wide public, as well as specific technical solutions.

Comments (2)

  1. Remieno says:

    I forgot – THANK YOU!

  2. Anthony Gee Tony Potter says:

    You are welcome.

Leave a Reply