4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

特定プロセスのメモリ使用率を監視するNagiosプラグイン

Posted at

こんな感じで書いてみました。

デプロイ方法はこちらをご覧ください。

#!/bin/bash -e
##-------------------------------------------------------------------
## File: check_memory_procs
## Author : Yutaka Hiroyama
## Description :
## --
##
## Created : <2015-08-05>
## 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 <warn_%> -c <criti_%> <pattern_proc>"
    echo ""
    echo "Copyright (C) 2015 Yutaka Hiroyama"
    exit
fi
4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?