#!/bin/bash
# Disk usage monitorization plugin for Pandora FMS agent
# Author: Manuel A. GulĂn Bejarano
# Version: 1.2
# Date: 19/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 "Disk 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 used swap - all retrieved with one query, later it's going to be appropiately parsed
SWP_INFO=`free -m | grep Swap:`
# 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)}'`
# Info about used disks - all retrieved with one query, later it's going to be appropiately parsed
DISK_INFO=`df -m | tail --lines=+2`
# Loop to iterate through disks; size info
df -Pm | tail --lines=+2 | while read line; do
DISK=`echo $line | awk '{print $1}'`
if [[ "$DISK" == /dev/sd* || "$DISK" == /dev/hd* || "$DISK" == /dev/mapper/* ]]; then
SPACE=`echo $line | awk '{print $2}'`
USAGE=`echo $line | awk '{print $3}'`
USAGE100=`echo $line | awk '{print $5}' | grep -o [0-9]*`
MOUNT=`echo $line | awk '{print $6}'`
# Module to get the total space on disk
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 free space on disk
echo -e "\t"
echo -e "\t"
echo -e "\t"
echo -e "\tgeneric_data"
echo -e "\tMB"
echo -e "\t0"
echo -e "\t0"
echo -e "\t"
echo -e "\t"
# Module to get the % of used space on disk
echo -e "\t"
echo -e "\t"
echo -e "\t"
echo -e "\tgeneric_data"
echo -e "\t%"
echo -e "\t0"
echo -e "\t100"
echo -e "\t85"
echo -e "\t89.9"
echo -e "\t90"
echo -e "\t100"
echo -e "\t0"
echo -e "\t"
echo -e "\t"
fi
done
# 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"
# Loop to iterate through disks; I/O info
for line in `ls /dev/{hd,sd}? 2> /dev/null`; do
DISK_D=`echo $line | cut -d "/" -f3`
IO_INFO=`iostat -m $DISK | grep $DISK_D`
if [ ! -z "$IO_INFO" ]; then
IO_TPS=`echo $IO_INFO | awk '{print $2}'`
IO_RMBS=`echo $IO_INFO | awk '{print $3}'`
IO_WMBS=`echo $IO_INFO | awk '{print $4}'`
# Module to get the transfers per second on disk
echo -e "\t"
echo -e "\t"
echo -e "\t"
echo -e "\tgeneric_data"
echo -e "\ttps"
echo -e "\t0"
echo -e "\t0"
echo -e "\t"
echo -e "\t"
# Module to get the read speed on disk
echo -e "\t"
echo -e "\t"
echo -e "\t"
echo -e "\tgeneric_data"
echo -e "\tMB/sec"
echo -e "\t0"
echo -e "\t0"
echo -e "\t"
echo -e "\t"
# Module to get the write speed on disk
echo -e "\t"
echo -e "\t"
echo -e "\t"
echo -e "\tgeneric_data"
echo -e "\tMB/sec"
echo -e "\t0"
echo -e "\t0"
echo -e "\t"
echo -e "\t"
fi
done