HiLoadMonitor

From campisano.org
Jump to navigation Jump to search

Questo script controlla il carico della CPU e invia una notifica per email in caso di problema.

NOTA: i comandi mail e bc devono essere accessibili.


#!/bin/sh
#
# hiLoadMonitor



# Var

EMAIL="email@server.whr";
SUBJECT="domain.whr hiLoadMonitor";
MAXLOAD=10;



# Test

if test ! `which mail`
then
   echo "Command mail not found, exit.";
   exit 1;
fi;

if test ! `which bc`
then
   echo "Command bc not found, exit." | mail -s "${SUBJECT} error." "${EMAIL}";
   exit 1;
fi;

if test ! `which top`
then
   echo "Command top not found, exit." | mail -s "${SUBJECT} error." "${EMAIL}";
   exit 1;
fi;



# Monitor

LOAD=$(cat /proc/loadavg | cut -f 1 -d ' ');

if test $(echo "${LOAD} > ${MAXLOAD}" | bc) -eq 1;
then
    top -b -n 1 | head -25 | mail -s "${SUBJECT} Alert! CPU load high: ${LOAD}" "${EMAIL}";
fi;



# End