From: David Galloway Date: Fri, 23 Sep 2016 20:24:16 +0000 (-0400) Subject: common: Add nagios check_mem command X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=4600aab694305d71dffa148105a0409b89a5ab0a;p=ceph-cm-ansible.git common: Add nagios check_mem command Signed-off-by: David Galloway --- diff --git a/roles/common/files/nagios/check_mem.sh b/roles/common/files/nagios/check_mem.sh new file mode 100644 index 0000000..5a0c103 --- /dev/null +++ b/roles/common/files/nagios/check_mem.sh @@ -0,0 +1,52 @@ +#!/bin/bash +# Source: https://github.com/whereisaaron/linux-check-mem-nagios-plugin + +if [ "$1" = "-w" ] && [ "$2" -gt "0" ] && [ "$3" = "-c" ] && [ "$4" -gt "0" ]; then + + freem=`free -m | grep Mem` + freem_bits=(${freem// / }) + + memTotal_m=${freem_bits[1]} + memFree_m=${freem_bits[3]} + memBuffer_m=${freem_bits[5]} + memCache_m=${freem_bits[6]} + + memUsed_m=$(($memTotal_m-$memFree_m-$memBuffer_m-$memCache_m)) + memUsedPrc=$((($memUsed_m*100)/$memTotal_m)) + + warn=$(((($memTotal_m*100)-($memTotal_m*(100-$2)))/100)) + crit=$(((($memTotal_m*100)-($memTotal_m*(100-$4)))/100)) + + memTotal_b=$(($memTotal_m*1024*1024)) + memFree_b=$(($memFree_m*1024*1024)) + memUsed_b=$(($memUsed_m*1024*1024)) + memBuffer_b=$(($memBuffer_m*1024*1024)) + memCache_b=$(($memCache_m*1024*1024)) + + minmax="0;$memTotal_b"; + data="TOTAL=$memTotal_b;;;$minmax USED=$memUsed_b;$warn;$crit;$minmax CACHE=$memCache_b;;;$minmax BUFFER=$memBuffer_b;;;$minmax" + + if [ "$memUsedPrc" -ge "$4" ]; then + echo "MEMORY CRITICAL - Total: $memTotal_m MB - Used: $memUsed_m MB - $memUsedPrc% used!|$data" + $(exit 2) + elif [ "$memUsedPrc" -ge "$2" ]; then + echo "MEMORY WARNING - Total: $memTotal_m MB - Used: $memUsed_m MB - $memUsedPrc% used!|$data" + $(exit 1) + else + echo "MEMORY OK - Total: $memTotal_m MB - Used: $memUsed_m MB - $memUsedPrc% used|$data" + $(exit 0) + fi + +else + echo "check_mem v1.3" + echo "" + echo "Usage:" + echo "check_mem.sh -w -c " + echo "" + echo "warnlevel and critlevel is percentage value without %" + echo "" + echo "v1.1 Copyright (C) 2012 Lukasz Gogolin (lukasz.gogolin@gmail.com)" + echo "v1.2 Modified 2014 by Aaron Roydhouse (aaron@roydhouse.com)" + echo "v1.3 Modified 2015 by Aaron Roydhouse (aaron@roydhouse.com)" + exit +fi diff --git a/roles/common/tasks/nagios.yml b/roles/common/tasks/nagios.yml index 934b872..1267c40 100644 --- a/roles/common/tasks/nagios.yml +++ b/roles/common/tasks/nagios.yml @@ -50,6 +50,14 @@ mode: 0440 validate: visudo -cf %s +- name: Upload nagios check_mem script + copy: + src: nagios/check_mem.sh + dest: "{{ nagios_plugins_directory }}/check_mem.sh" + owner: root + group: root + mode: 0755 + - name: Configure nagios nrpe settings (Ubuntu) lineinfile: dest: /etc/default/{{ nrpe_service_name }} diff --git a/roles/common/templates/nagios/nrpe.cfg b/roles/common/templates/nagios/nrpe.cfg index 3aabc16..b59c3a8 100644 --- a/roles/common/templates/nagios/nrpe.cfg +++ b/roles/common/templates/nagios/nrpe.cfg @@ -13,6 +13,7 @@ connection_timeout=300 command[check_users]={{ nagios_plugins_directory }}/check_users --warning=5 --critical=10 command[check_load]={{ nagios_plugins_directory }}/check_load --percpu --warning=1.5,1.4,1.3 --critical=2.0,1.9,1.8 +command[check_mem]={{ nagios_plugins_directory }}/check_mem.sh -w 85 -c 95 command[check_hda1]={{ nagios_plugins_directory }}/check_disk --warning=20% --critical=10% --partition=/dev/hda1 command[check_root]={{ nagios_plugins_directory }}/check_disk --warning=10% --critical=5% --units=GB --path=/ command[check_zombie_procs]={{ nagios_plugins_directory }}/check_procs --warning=5 --critical=10 --state=Z