监控MFS服务器的nagios插件脚本,具体内容如下,有需要的可以在其基础上进行修改。

  1#!/bin/bash
  2# Nagios return codes
  3STATE_OK=0
  4STATE_WARNING=1
  5STATE_CRITICAL=2
  6STATE_UNKNOWN=3
  7# Set MFS Path And Warning/CRITICAL Value
  8MFS_Path="/usr/sbin"
  9MFS_Mount_Point="/mnt/mfs"
 10WARNING_Value=85
 11CRITICAL_Value=95
 12#Get Master server Process
 13Master(){
 14MFS_PID=`ps -ef | grep mfsmaster | grep ${mfspath} | awk '{print $2}'`
 15if [ "${MFS_PID}" = "" ];then
 16    echo "ERROR : mfs master does not start"
 17    exit $STATE_CRITICAL
 18else
 19    echo "OK : mfs master server running OK!"
 20     exit $STATE_OK
 21fi
 22}
 23#Get chunker server Process
 24Chunker(){
 25MFS_PID=`ps -ef | grep mfschunkserver | grep ${mfspath} | awk '{print $2}'`
 26if [ "${MFS_PID}" = "" ];then
 27    echo "ERROR : mfs chunkserver does not start"
 28    exit $STATE_CRITICAL
 29else
 30    echo "OK : mfs master chunkserver running OK!"
 31    exit $STATE_OK
 32fi
 33}
 34Disk_used(){
 35Disk_used=`df -h | grep ${mountpoint} | awk '{print $5}' | awk -F% '{print $1}'`
 36if [ ${Disk_used} -ge ${warningdiskused} -a ${Disk_used} -lt ${criticaldiskused} ];then
 37    echo "Waring :mfs disk used Rate is "${Disk_used}""
 38    exit $STATE_WARNING
 39elif [ ${Disk_used} -ge ${criticaldiskused} ];then
 40    echo "CRITICAL :mfs disk used Rate is "${Disk_used}""
 41    exit $STATE_CRITICAL
 42elif [ "${Disk_used}" = "" ];then
 43    echo "CRITICAL :mfs client not mount on"
 44    exit $STATE_CRITICAL
 45else
 46    echo "OK : MFS client mount on and disk used rate is ${Disk_used}% , Everything is OK!"
 47    exit $STATE_OK
 48fi
 49}
 50#Get metalogger server Process
 51Metalogger(){
 52MFS_PID=`ps -ef | grep mfsmetalogger | grep ${mfspath} | awk '{print $2}'`
 53if [ "${MFS_PID}" = "" ];then
 54    echo "ERROR : mfs mfsmetalogger does not start"
 55    exit $STATE_CRITICAL
 56else
 57    echo "OK : mfs master mfsmetalogger running OK!"
 58    exit $STATE_OK
 59fi
 60}
 61# Functions plugin usage
 62print_usage()
 63{
 64    Program_name=$(basename $0)
 65    echo ""
 66    echo " -M MFS master server status "
 67    echo " -C MFS chunker server status "
 68    echo " -U MFS client disk used Rate "
 69    echo " -L MFS metalogger server status "
 70    echo " -h Show this page "
 71    echo ""
 72    echo " Usage1 : ${Program_name} -M mfsmasterpath"
 73    echo "    ex : ${Program_name} -M ${MFS_Path}"
 74    echo " Usage2 : ${Program_name} -C mfschunkpath"
 75    echo "    ex : ${Program_name} -C ${MFS_Path}"
 76    echo " Usage3 : ${Program_name} -U mountpoint warningrate criticalrate"
 77    echo "    ex : ${Program_name} -U ${MFS_Mount_Point} 60 80"
 78    echo " Usage4 : ${Program_name} -L mfsmetaloggerpath"
 79    echo "    ex : ${Program_name} -L ${MFS_Path}"
 80    echo "     ex : ${Program_name} -h"
 81    echo ""
 82    exit 0
 83}
 84# Parse parameter
 85while [ $# -gt 0 ]
 86do
 87    case "$1" in
 88        -h | --help)
 89            print_usage
 90            exit $STATE_OK
 91            ;;
 92        -M | --master)
 93            mfspath=${2:-"${MFS_Path}"}
 94            Master
 95            ;;
 96        -C | --chunker)
 97            mfspath=${2:-"${MFS_Path}"}
 98            Chunker
 99            ;;
100        -U | --usedwarning)
101            mountpoint=${2:-"${MFS_Mount_Point}"}
102            warningdiskused=${3:-"${WARNING_Value}"}
103            criticaldiskused=${4:-"${CRITICAL_Value}"}
104            Disk_used
105                        ;;
106        -L | --metalogger)
107            mfspath=${2:-"${MFS_Path}"}
108            Metalogger
109            ;;
110        *)
111            echo "Unknown argement: $1"
112            exit $STATE_UNKNOWN
113            ;;
114    esac
115shift
116done