#!/bin/bash
# Memory usage monitorization plugin for Pandora FMS agent
# Author: Manuel A. GulĂn Bejarano
# Version: 1.0
# Date: 15/03/2013
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
function help {
echo -e "Memory usage monitorization agent plugin for Pandora FMS agent. http://pandorafms.com"
echo -e "Syntax:"
echo -e "\t\t$0"
exit
}
if [ $# -ne 0 ]
then
help
exit -1
fi
# Info about swap memory - all retrieved with one query, later it's going to be appropiately parsed
MEM_INFO=`free -m | grep Mem:`
# Info about swap memory - all retrieved with one query, later it's going to be appropiately parsed
MEMAPP_INFO=`free -m | grep cache:`
# Info about swap memory - all retrieved with one query, later it's going to be appropiately parsed
SWP_INFO=`free -m | grep Swap:`
# Info about memory - from the kernel's standpoint
MEM_SPACE=`echo $MEM_INFO | awk '{print $2}'`
MEM_USAGE=`echo $MEM_INFO | awk '{print $3}'`
MEM_FREE=`echo $MEM_INFO | awk '{print $4}'`
MEM_SHARED=`echo $MEM_INFO | awk '{print $5}'`
MEM_BUFF=`echo $MEM_INFO | awk '{print $6}'`
MEM_CACHE=`echo $MEM_INFO | awk '{print $7}'`
MEM_USAGE100=`echo $MEM_USAGE $MEM_SPACE | awk '{if ($2>0) {print int(10000*$1/$2)/100} else {print 0}}'`
MEM_BUFF100=`echo $MEM_BUFF $MEM_SPACE | awk '{if ($2>0) {print int(10000*$1/$2)/100} else {print 0}}'`
MEM_CACHE100=`echo $MEM_CACHE $MEM_SPACE | awk '{if ($2>0) {print int(10000*$1/$2)/100} else {print 0}}'`
# Info about memory - from the application's standpoint
MEMAPP_USAGE=`echo $MEMAPP_INFO | awk '{print $3}'`
MEMAPP_FREE=`echo $MEMAPP_INFO | awk '{print $4}'`
MEMAPP_FREE100=`echo $MEMAPP_FREE $MEM_SPACE | awk '{if ($2>0) {print int(10000*$1/$2)/100} else {print 0}}'`
# Info about swap
SWP_SPACE=`echo $SWP_INFO | awk '{print $2}'`
SWP_USAGE=`echo $SWP_INFO | awk '{print $3}'`
SWP_USAGE100=`echo "$SWP_USAGE $SWP_SPACE" | awk '{print ($1*100/$2)}'`
# Module to get the total RAM
echo -e "\t"
echo -e "\t"
echo -e "\t"
echo -e "\tasync_data"
echo -e "\tMB"
echo -e "\t0"
echo -e "\t0"
echo -e "\t"
#echo -e "\t0 * * * *""
echo -e "\t"
# Module to get the used RAM from the kernel standpoint
echo -e "\t"
echo -e "\t"
echo -e "\t"
echo -e "\tgeneric_data"
echo -e "\tMB"
echo -e "\t0"
echo -e "\t$MEM_SPACE"
echo -e "\t0"
echo -e "\t"
echo -e "\t"
# Module to get the free RAM from the kernel standpoint
echo -e "\t"
echo -e "\t"
echo -e "\t"
echo -e "\tgeneric_data"
echo -e "\tMB"
echo -e "\t0"
echo -e "\t$MEM_SPACE"
echo -e "\t0"
echo -e "\t"
echo -e "\t"
# Module to get the shared RAM
echo -e "\t"
echo -e "\t"
echo -e "\t"
echo -e "\tgeneric_data"
echo -e "\tMB"
echo -e "\t0"
echo -e "\t$MEM_SPACE"
echo -e "\t0"
echo -e "\t"
echo -e "\t"
# Module to get the RAM used by buffers
echo -e "\t"
echo -e "\t"
echo -e "\t"
echo -e "\tgeneric_data"
echo -e "\tMB"
echo -e "\t0"
echo -e "\t$MEM_SPACE"
echo -e "\t0"
echo -e "\t"
echo -e "\t"
# Module to get the RAM used by cache
echo -e "\t"
echo -e "\t"
echo -e "\t"
echo -e "\tgeneric_data"
echo -e "\tMB"
echo -e "\t0"
echo -e "\t$MEM_SPACE"
echo -e "\t0"
echo -e "\t"
echo -e "\t"
# Module to get the percentage of used RAM from the kernel standpoint
echo -e "\t"
echo -e "\t"
echo -e "\t"
echo -e "\tgeneric_data"
echo -e "\t%"
echo -e "\t0"
echo -e "\t100"
echo -e "\t95"
echo -e "\t98.99"
echo -e "\t99"
echo -e "\t100"
echo -e "\t0"
echo -e "\t"
echo -e "\t"
# Module to get the percentage of RAM used by buffers
echo -e "\t"
echo -e "\t"
echo -e "\t"
echo -e "\tgeneric_data"
echo -e "\t%"
echo -e "\t0"
echo -e "\t100"
echo -e "\t0"
echo -e "\t1"
echo -e "\t1.01"
echo -e "\t5"
echo -e "\t0"
echo -e "\t"
echo -e "\t"
# Module to get the percentage of RAM used by cache
echo -e "\t"
echo -e "\t"
echo -e "\t"
echo -e "\tgeneric_data"
echo -e "\t%"
echo -e "\t0"
echo -e "\t100"
echo -e "\t0"
echo -e "\t1"
echo -e "\t1.01"
echo -e "\t5"
echo -e "\t0"
echo -e "\t"
echo -e "\t"
# Module to get the used RAM from the applications standpoint
echo -e "\t"
echo -e "\t"
echo -e "\t"
echo -e "\tgeneric_data"
echo -e "\tMB"
echo -e "\t0"
echo -e "\t$MEM_SPACE"
echo -e "\t0"
echo -e "\t"
echo -e "\t"
# Module to get the free RAM from the applications standpoint
echo -e "\t"
echo -e "\t"
echo -e "\t"
echo -e "\tgeneric_data"
echo -e "\tMB"
echo -e "\t0"
echo -e "\t$MEM_SPACE"
echo -e "\t0"
echo -e "\t"
echo -e "\t"
# Module to get the percentage of free RAM from the applications standpoint
echo -e "\t"
echo -e "\t"
echo -e "\t"
echo -e "\tgeneric_data"
echo -e "\t%"
echo -e "\t0"
echo -e "\t100"
echo -e "\t0"
echo -e "\t5"
echo -e "\t5.01"
echo -e "\t15"
echo -e "\t0"
echo -e "\t"
echo -e "\t"
# Module to get the total swap space
echo -e "\t"
echo -e "\t"
echo -e "\t"
echo -e "\tasync_data"
echo -e "\tMB"
echo -e "\t0"
echo -e "\t0"
echo -e "\t"
#echo -e "\t0 * * * *""
echo -e "\t"
# Module to get the used swap space
echo -e "\t"
echo -e "\t"
echo -e "\t"
echo -e "\tgeneric_data"
echo -e "\tMB"
echo -e "\t0"
echo -e "\t$SWP_SPACE"
echo -e "\t100"
echo -e "\t499"
echo -e "\t500"
echo -e "\t$SWP_SPACE"
echo -e "\t0"
echo -e "\t"
echo -e "\t"
# Module to get the % of used swap space
echo -e "\t"
echo -e "\t"
echo -e "\t"
echo -e "\tgeneric_data"
echo -e "\t%"
echo -e "\t0"
echo -e "\t100"
echo -e "\t40"
echo -e "\t89.9"
echo -e "\t90"
echo -e "\t100"
echo -e "\t0"
echo -e "\t"
echo -e "\t"