Browse Source
new: [send] add cron hourly for disk_usage and load_average_max
new: [send] add cron hourly for disk_usage and load_average_max
Boris Gallet
10 months ago
8 changed files with 268 additions and 22 deletions
-
48bin/myc-install
-
56bin/myc-update
-
62bin/send
-
4etc/cron.d/monitor
-
31etc/cron.daily/check_backup
-
7etc/cron.daily/remove_lock_file_48h
-
42etc/cron.hourly/disk_usage
-
32etc/cron.hourly/load_average_max
@ -1,4 +0,0 @@ |
|||||
SHELL=/bin/bash |
|
||||
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin |
|
||||
|
|
||||
*/2 * * * * root lock vps-stats -v -D -p 10 -k -c "vps stats -s" 2>&1 | logger -t stats |
|
@ -0,0 +1,31 @@ |
|||||
|
#!/bin/bash |
||||
|
|
||||
|
SHELL=/bin/bash |
||||
|
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin |
||||
|
|
||||
|
## Check on daily bases if backup exist in config and when is the last backup done : |
||||
|
## ALERT if backup is set and last backup is older than 24h |
||||
|
|
||||
|
LOCK_WORKING_DIR="/var/run/myc-manage" |
||||
|
mkdir -p "$LOCK_WORKING_DIR" |
||||
|
|
||||
|
IS_BACKUP_SET=$(cat /opt/apps/myc-deploy/compose.yml </dev/null | grep backup) |
||||
|
if [ -z "$IS_BACKUP_SET" ]; then |
||||
|
date_last_backup=$(cat /srv/datastore/data/cron/var/log/cron/rsync-backup_script.log | grep "total size is" | tail -1 | cut -f -2 -d " ") |
||||
|
if [ -z "$date_last_backup" ]; then |
||||
|
backup_timestamp=$(date -d "$date_last_backup" +%s) |
||||
|
max_timestamp=$(date -d "24 hours ago" +%s) |
||||
|
if [ "$backup_timestamp" -lt "$max_timestamp" ]; then |
||||
|
if [ -e $LOCK_WORKING_DIR/check_backup.lock ]; then |
||||
|
exit 0 |
||||
|
else |
||||
|
touch $LOCK_WORKING_DIR/check_backup.lock |
||||
|
message="$(hostname): WARNING no backup done in the last 24h" |
||||
|
send "$message" |
||||
|
fi |
||||
|
else |
||||
|
if [ -e $LOCK_WORKING_DIR/check_backup.lock ]; then |
||||
|
rm $LOCK_WORKING_DIR/check_backup.lock |
||||
|
fi |
||||
|
fi |
||||
|
fi |
@ -0,0 +1,7 @@ |
|||||
|
#!/bin/bash |
||||
|
|
||||
|
SHELL=/bin/bash |
||||
|
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin |
||||
|
|
||||
|
## Remove every .lock file older than 48h -- CLeanup script |
||||
|
find /var/run/myc-manage -name "*.lock" -type f -mtime +2 -delete |
@ -0,0 +1,42 @@ |
|||||
|
#!/bin/bash |
||||
|
|
||||
|
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%\%} |
||||
|
|
||||
|
LOCK_WORKING_DIR="/var/run/myc-manage" |
||||
|
mkdir -p "$LOCK_WORKING_DIR" |
||||
|
|
||||
|
if [ "$percent_usage" -ge "90" ]; then |
||||
|
if [ -e $LOCK_WORKING_DIR/disk_usage_90.lock ]; then |
||||
|
exit 0 |
||||
|
else |
||||
|
touch $LOCK_WORKING_DIR/disk_usage_90.lock |
||||
|
message="$(hostname): WARNING disk usage >=90%" |
||||
|
send "$message" |
||||
|
fi |
||||
|
elif [ "$percent_usage" -ge "75" ]; then |
||||
|
if [ -e $LOCK_WORKING_DIR/disk_usage_75.lock ]; then |
||||
|
exit 0 |
||||
|
else |
||||
|
touch $LOCK_WORKING_DIR/disk_usage_75.lock |
||||
|
message="$(hostname): WARNING disk usage >=75 <90%" |
||||
|
send "$message" |
||||
|
fi |
||||
|
else |
||||
|
if [ -e $LOCK_WORKING_DIR/disk_usage_75.lock ]; then |
||||
|
rm $LOCK_WORKING_DIR/disk_usage_75.lock |
||||
|
fi |
||||
|
if [ -e $LOCK_WORKING_DIR/disk_usage_90.lock ]; then |
||||
|
rm $LOCK_WORKING_DIR/disk_usage_90.lock |
||||
|
fi |
||||
|
fi |
||||
|
|
||||
|
|
@ -0,0 +1,32 @@ |
|||||
|
#!/bin/bash |
||||
|
|
||||
|
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 |
||||
|
|
||||
|
LOCK_WORKING_DIR="/var/run/myc-manage" |
||||
|
mkdir -p "$LOCK_WORKING_DIR" |
||||
|
|
||||
|
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 $LOCK_WORKING_DIR/load_average_max.lock ]; then |
||||
|
exit 0 |
||||
|
else |
||||
|
touch $LOCK_WORKING_DIR/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 "$message" |
||||
|
fi |
||||
|
else |
||||
|
if [ -e $LOCK_WORKING_DIR/load_average_max.lock ]; then |
||||
|
rm $LOCK_WORKING_DIR/load_average_max.lock |
||||
|
fi |
||||
|
fi |
Write
Preview
Loading…
Cancel
Save
Reference in new issue