こんな感じで書いてみました。
デプロイ方法はこちらをご覧ください。
#!/bin/bash -e ##------------------------------------------------------------------- ## File: check_memory_procs ## Author : Yutaka Hiroyama ## Description : ## -- ## ## Created : ## Updated: Time-stamp: ##------------------------------------------------------------------- if [ "$1" = "-w" ] && [ "$2" -gt "0" ] && [ "$3" = "-c" ] && [ "$4" -gt "0" ]; then procpattern=${5} total=`grep "MemTotal" /proc/meminfo | awk -F' ' '{print $2}'` memVmSize=`ps aux | grep "$procpattern" | grep -v grep | grep -v check_proc_mem.sh | awk '{sum += $6} END {print sum}'` per=$((($memVmSize*100)/$total)) memVmSize=$(($memVmSize/1024)) if [ "$per" -ge "$4" ]; then echo "Memory: CRITICAL - $procpattern using $memVmSize MB ($per %)" $(exit 2) elif [ "$per" -ge "$2" ]; then echo "Memory: WARNING - $procpattern using $memVmSize MB ($per %)" $(exit 1) else echo "Memory: OK - $procpattern using $memVmSize MB ($per %)" $(exit 0) fi else echo "check_memory_procs v1.0" echo "" echo "Usage:" echo "check_memory_procs -w-c " echo "" echo "Copyright (C) 2015 Yutaka Hiroyama" exit fi