Browse Source

new: [send] add cron hourly for disk_usage and load_average_max

Boris Gallet 9 months ago
parent
commit
eb3efe6c17
  1. 1
      bin/myc-update
  2. 3
      etc/cron.d/alerting
  3. 35
      etc/cron.hourly/disk_usage
  4. 23
      etc/cron.hourly/load_average_max

1
bin/myc-update

@ -62,6 +62,7 @@ EOF
Wrap -d "Updating cron scripts" <<EOF || exit 1
ln -sfn /opt/apps/myc-manage/etc/cron.d/* /etc/cron.d/
ln -sfn /opt/apps/myc-manage/etc/cron.hourly/* /etc/cron.hourly/
find -L /etc/cron.d -maxdepth 1 -type l -ilname /opt/apps/myc-manage/etc/cron.d/\* -delete
EOF

3
etc/cron.d/alerting

@ -0,0 +1,3 @@
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

35
etc/cron.hourly/disk_usage

@ -0,0 +1,35 @@
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
## check disk usage and send a notification if it's above 75% or 90%
percent_usage=$(df /srv -h)
percent_usage=${percent_usage##*$'\n'}
percent_usage=${percent_usage% *}
percent_usage=${percent_usage##* }
percent_usage=${percent_usage%\%}
if [ "$percent_usage" -ge "90" ]; then
if [ -e /tmp/disk_usage_90.lock ]; then
exit 0
else
touch /tmp/disk_usage_90.lock
message="$(hostname): WARNING disk usage >=90%"
send "disk_usage" "$message"
fi
elif [ "$percent_usage" -ge "75" ]; then
if [ -e /tmp/disk_usage_75.lock ]; then
exit 0
else
touch /tmp/disk_usage_75.lock
message="$(hostname): WARNING disk usage >=75 <90%"
send "disk_usage" "$message"
fi
else
if [ -e /tmp/disk_usage_75.lock ]; then
rm /tmp/disk_usage_75.lock
fi
if [ -e /tmp/disk_usage_90.lock ]; then
rm /tmp/disk_usage_90.lock
fi
fi

23
etc/cron.hourly/load_average_max

@ -0,0 +1,23 @@
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
MAX_PER_PROC=3
## integer only for the 5m load avg
int_avg=$(while read line; do
echo "$line"
done < /proc/loadavg)
int_avg=${int_avg#* }
int_avg=${int_avg%%.*}
max=$[$MAX_PER_PROC * $(grep -c ^processor /proc/cpuinfo)]
if [ "$int_avg" -gt "$max" ]; then
if [ -e /tmp/load_average_max.lock ]; then
exit 0
else
touch /tmp/load_average_max.lock
message="$(hostname) : WARNING - load average ($int_avg) is above max per processor : ($MAX_PER_PROC * $(grep -c ^processor /proc/cpuinfo) = $max)"
echo $message | logger -t load_average_max
send "load_average_max" "$message"
fi
fi
Loading…
Cancel
Save