forked from magenx/Magento-2-server-installation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload_alert.sh
More file actions
29 lines (23 loc) · 790 Bytes
/
load_alert.sh
File metadata and controls
29 lines (23 loc) · 790 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash
# Configuration
LOAD_THRESHOLD=3
EMAIL_TO="ADMIN_EMAIL"
EMAIL_SUBJECT="High Load Average Alert on $(hostname)"
# Get the 1-minute load average
LOAD_AVERAGE=$(uptime | awk -F'[a-z]:' '{ print $2 }' | awk -F', ' '{ print $1 }' | tr -d ' ')
# Get conneted IPs qty
ESTABLISHED=$(ss -ntp state established 'sport = :443' | awk '{print $4}' | cut -d: -f1 | sort -u | wc -l)
# Compare the load average with the threshold
if (( $(echo "${LOAD_AVERAGE} > ${LOAD_THRESHOLD}" | bc -l) )); then
EMAIL_BODY=$(cat <<EOF
Warning: High load average detected on $(hostname)
Time: $(date)
1-minute load average: ${LOAD_AVERAGE}
Threshold: ${LOAD_THRESHOLD}
Connections: ${ESTABLISHED}
System information:
$(uptime)
EOF
)
echo "${EMAIL_BODY}" | mail -s "${EMAIL_SUBJECT}" "${EMAIL_TO}"
fi