[MDRM] 시스템 모니터링 플러그인

Table of Contents

Symptoms

  •  모니터링 플러그인 추가시 시스템 모니터링을 하기 위한 스크립트 정리
  •  Linux,Windows,HP-UX 운영체제의 CPU, MEM, DISK, PROCESS 사용량 확인 가능

Environment

   1. 모니터링 플러그인 등록(웹페이지)

   2. 관제서버 NAGIOS 설정파일 설정(mccs_commands.cfg)

example ) 

image-1602571176361.png

   3. gam 컨테이너에서 해당 모니터링 스크립트 생성

Solution

1. Memory 사용량 확인

#!/bin/sh
IP_ADDRESS=$1
OS_TYPE=$2

case ${OS_TYPE} in
  linux | LINUX)
    echo "ChartValue=`/gampkgs/scripts/agent/agent_monitor.py $1 -c "free|grep ^Mem" | awk '{printf "%.0f", $3/$2*100}'`"
    ;;
  windows | WINDOWS)
    echo "ChartValue=`/gampkgs/scripts/agent/agent_monitor.py $1 -c 'typeperf "\memory\% committed bytes in use" -sc 1'| sed -n '2p' | awk -F '"' '{print $4}'`"
    ;;
  hpux | HPUX)
    echo "ChartValue=`/gampkgs/scripts/agent/agent_monitor.py $1 -c "dmesg |grep Physical"| awk '{printf "%.0f", ( $2 - $8 )/$2*100}'`"
    ;;
esac


2. CPU 사용량 확인

#!/bin/sh
IP_ADDRESS=$1
OS_TYPE=$2

case ${OS_TYPE} in
  linux | LINUX)
    echo "ChartValue=`/gampkgs/scripts/agent/agent_monitor.py $1 -c "mpstat | tail -1" | awk '{print 100-$NF}'`"
    ;;
  
  windows | WINDOWS)
    echo "ChartValue=`/gampkgs/scripts/agent/agent_monitor.py $1 -c "wmic cpu get loadpercentage"| tail -n 1`"
    ;;
  hpux | HPUX)
    echo "ChartValue=`/gampkgs/scripts/agent/agent_monitor.py $1 -c "sar 1 1|sed -n '5p'"|awk '{printf "%0.f",100-$5}'`"
    ;;
esac


3. DISK 사용량 확인

#!/bin/sh
IP_ADDRESS=$1
OS_TYPE=$2
DISK_NAME=$3

case ${OS_TYPE} in
  linux | LINUX)
    echo "ChartValue=`/gampkgs/scripts/agent/agent_monitor.py $1 -c "df -hT|grep ${DISK_NAME}" | awk '{print $6}' | cut -d"%" -f1`"
    ;;
  windows | WINDOWS)
    echo "ChartValue=`/gampkgs/scripts/agent/agent_monitor.py $1 -c "wmic logicaldisk get deviceid,size,freespace|findstr ${DISK_NAME}" |awk '{printf "%.0f", ( $3 - $2 )/$3*100}'`"
    ;;
  hpux | HPUX)
    echo "ChartValue=`/gampkgs/scripts/agent/agent_monitor.py $1 -c bdf|grep ${DISK_NAME} | awk '{print $5}' | cut -d"%" -f1`"
    ;;
esac


4.  Process 기동 상태 확인

#!/bin/sh
IP_ADDRESS=$1
OS_TYPE=$2
PROC_NAME=$3
RUN_USER=$4

case ${OS_TYPE} in
  linux | LINUX)
    /gampkgs/scripts/agent/agent_monitor.py $1 -c "ps -ef|grep ${RUN_USER}|grep ${PROC_NAME}|grep -v grep|grep -v tail" | grep ${PROC_NAME} > /dev/null
    if [ $? -eq 0 ]
    then
    echo "ChartValue=0"
    else
    echo "ChartValue=1"
    fi
    ;;
  windows | WINDOWS)
    /gampkgs/scripts/agent/agent_monitor.py $1 -c "tasklist |findstr ${PROC_NAME}" | grep ${PROC_NAME} > /dev/null
    if [ $? -eq 0 ]
    then
    echo "ChartValue=0"
    else
    echo "ChartValue=1"
    fi
    ;;
  hpux | HPUX)
    /gampkgs/scripts/agent/agent_monitor.py $1 -c "ps -efx|grep ${RUN_USER}|grep ${PROC_NAME}|grep -v grep|grep -v tail" | grep ${PROC_NAME} > /dev/null
    if [ $? -eq 0 ]
    then
    echo "ChartValue=0"
    else
    echo "ChartValue=1"
    fi
    ;;
esac

  #