46 lines
1.4 KiB
Bash
46 lines
1.4 KiB
Bash
#!/bin/bash
|
|
# Usage: "Linux - RAM usage monitor.sh 80 95"
|
|
#
|
|
# Description:
|
|
# This script is used from inside of Tactical RMM instances to check the RAM usage.
|
|
# This script should be deployed as a check script.
|
|
#
|
|
# Options:
|
|
# Arg1 - Warning limit
|
|
# Arg2 - Error limit
|
|
#
|
|
# Author: D. de Kooker (info@dcomputers.nl)
|
|
# Sources: https://www.activexperts.com/support/network-monitor/online/linux/
|
|
# Changelog :
|
|
# 27-06-2022 - Initial script from source, tweaked for my environment
|
|
# 16-09-2023 - Changed the way the RAM performance is monitored to TOP, because of false positives in alerting.
|
|
|
|
# Default values for WARNING and ERROR limits (in percentage)
|
|
WARNING_LIMIT=85
|
|
ERROR_LIMIT=95
|
|
|
|
# Check for command line arguments
|
|
if [ $# -eq 2 ]; then
|
|
WARNING_LIMIT=$1
|
|
ERROR_LIMIT=$2
|
|
fi
|
|
|
|
# Function to check RAM usage
|
|
check_ram_usage() {
|
|
RAM_TOTAL=$(free -m | awk '/^Mem:/ {print $2}')
|
|
RAM_USED=$(free -m | awk '/^Mem:/ {print $3}')
|
|
RAM_USAGE_PERCENTAGE=$(echo "scale=2; $RAM_USED / $RAM_TOTAL * 100" | bc)
|
|
|
|
if [ "$(echo "$RAM_USAGE_PERCENTAGE >= $ERROR_LIMIT" | bc -l)" -eq 1 ]; then
|
|
echo "ERROR: RAM usage is ${RAM_USAGE_PERCENTAGE}% (>= ${ERROR_LIMIT}%)"
|
|
exit 1
|
|
elif [ "$(echo "$RAM_USAGE_PERCENTAGE >= $WARNING_LIMIT" | bc -l)" -eq 1 ]; then
|
|
echo "WARNING: RAM usage is ${RAM_USAGE_PERCENTAGE}% (>= ${WARNING_LIMIT}%)"
|
|
exit 2
|
|
else
|
|
echo "OK: RAM usage is ${RAM_USAGE_PERCENTAGE}%"
|
|
exit 0
|
|
fi
|
|
}
|
|
|
|
check_ram_usage |