]> git.apps.os.sepia.ceph.com Git - ceph-cm-ansible.git/commitdiff
common: Add nagios check_mem command 283/head
authorDavid Galloway <dgallowa@redhat.com>
Fri, 23 Sep 2016 20:24:16 +0000 (16:24 -0400)
committerDavid Galloway <dgallowa@redhat.com>
Fri, 23 Sep 2016 20:27:05 +0000 (16:27 -0400)
Signed-off-by: David Galloway <dgallowa@redhat.com>
roles/common/files/nagios/check_mem.sh [new file with mode: 0644]
roles/common/tasks/nagios.yml
roles/common/templates/nagios/nrpe.cfg

diff --git a/roles/common/files/nagios/check_mem.sh b/roles/common/files/nagios/check_mem.sh
new file mode 100644 (file)
index 0000000..5a0c103
--- /dev/null
@@ -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 <warnlevel> -c <critlevel>"
+        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
index 934b872c43ca7f3f8ade57e9e9d14f0b2e9954ae..1267c40356e441d4f4637e7fc4de22ff46c9de5c 100644 (file)
     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 }}
index 3aabc163e141868ff6932534b3a6f0276a3ae7e7..b59c3a82a0df7f4a08d0e0f213e684f04973617d 100644 (file)
@@ -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