Add Check_scripts/Linux - RAM usage monitor.sh
This commit is contained in:
55
Check_scripts/Linux - RAM usage monitor.sh
Normal file
55
Check_scripts/Linux - RAM usage monitor.sh
Normal file
@@ -0,0 +1,55 @@
|
||||
#!/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
|
||||
|
||||
#region Parameters, functions and global variables
|
||||
nWarnMemoryUsage=$1
|
||||
nMaxMemoryUsage=$2
|
||||
#endregion
|
||||
# Validate number of arguments
|
||||
if [ $# -ne 2 ] ; then
|
||||
echo "UNCERTAIN: Invalid number of arguments - Usage: memory nMaxMemoryUsage"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Validate numeric parameter nMaxMemoryUsage
|
||||
regExpNumber='^[0-9]+$'
|
||||
if ! [[ $1 =~ $regExpNumber ]] ; then
|
||||
echo "UNCERTAIN: Invalid argument: nMaxMemoryUsage (number expected)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check the memory usage
|
||||
nMemoryPercentage=`ps -A -o pmem | tail -n+2 | paste -sd+ | bc`
|
||||
nMemoryPercentage=$( echo "$nMemoryPercentage / 1" | bc )
|
||||
|
||||
if [ $nMemoryPercentage -le $nWarnMemoryUsage ] ; then
|
||||
echo "SUCCESS: Memory usage is [$nMemoryPercentage%]"
|
||||
echo ""
|
||||
echo "Warning limit=[$1%], Error limit=[$2%]"
|
||||
exit 0
|
||||
fi
|
||||
if [ $nMemoryPercentage -gt $nWarnMemoryUsage -a $nMemoryPercentage -le $nMaxMemoryUsage ] ; then
|
||||
echo "WARNING: Memory usage is [$nMemoryPercentage%]"
|
||||
echo ""
|
||||
echo "Warning limit=[$1%], Error limit=[$2%]"
|
||||
exit 2
|
||||
fi
|
||||
if [ $nMemoryPercentage -gt $nMaxMemoryUsage ] ; then
|
||||
echo "ERROR: Memory usage is [$nMemoryPercentage%]"
|
||||
echo ""
|
||||
echo "Warning limit=[$1%], Error limit=[$2%]"
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user