memory.sh - ssh script by ActiveXperts Software
memory.sh checks memory usage of memory available on a host.
Use memory.sh directly from ActiveXperts Network Monitor; in the Manager's 'Monitor' menu, select 'New Check (Script)' and select memory.sh. Configure the required parameter, or press 'Load a working sample'.
In ActiveXperts Network Monitor, Administrators can use three different scripting languages: Powershell, VBScript and SSH.
memory.sh script code
#################################################################################
# ActiveXperts Network Monitor - Shell script checks
# © 1999-2015, ActiveXperts Software B.V.
#
# For more information about ActiveXperts Network Monitor and SSH, please
# visit the online ActiveXperts Network Monitor Shell Script Guidelines at:
# http://www.activexperts.com/support/network-monitor/online/linux/
#################################################################################
# Script
# memory.sh
# Description
# Checks the free or used memory
# Declare Parameters
# 1) free|used (string) - Define what to check, free or used memory
# 2) size_MB (string) - Size limit
# Usage
# memory.sh <free|used> <size_MB>
# Sample
# memory.sh free 20
#################################################################################
#!/bin/sh
# Macro definitiions
FREEMEM=`free -m | awk '/^Mem:/ { printf( "%s\n", $4 ); }'`
USEDMEM=`free -m | awk '/^Mem:/ { printf( "%s\n", $3 ); }'`
# Validate number of arguments
if [ $# -ne 2 ] ; then
echo "UNCERTAIN: Invalid number of arguments - Usage: memory <free|used> <size_MB>";
exit 1;
fi
# Validate arguments
if [ $1 != "free" ] && [ $1 != "used" ]; then
echo "ERROR: Invalid parameter: $1 DATA:0";
fi
# Check free memory
if [ $1 == "free" ] ; then
if [ $FREEMEM -ge $2 ] ; then
echo "SUCCESS: Free memory is [$FREEMEM MB], minimum required=[$2 MB] DATA:$FREEMEM";
else
echo "ERROR: Free memory is [$FREEMEM MB], minimum required=[$2 MB] DATA:$FREEMEM";
fi
fi
# Check used memory
if [ $1 == "used" ] ; then
if [ $USEDMEM -le $2 ] ; then
echo "SUCCESS: Used memory is [$USEDMEM MB], maximum allowed=[$2 MB] DATA:$USEDMEM";
else
echo "ERROR: Used memory is [$USEDMEM MB], maximum allowed=[$2 MB] DATA:$USEDMEM";
fi
fi
