Merge ~jk0ne/charm-nrpe:check_swap_activity into ~nrpe-charmers/charm-nrpe:master

Proposed by Jay Kuri
Status: Merged
Merged at revision: 33e5acd25a06db05bfc3932d671f6475c4f26ae8
Proposed branch: ~jk0ne/charm-nrpe:check_swap_activity
Merge into: ~nrpe-charmers/charm-nrpe:master
Diff against target: 148 lines (+99/-1)
4 files modified
config.yaml (+5/-1)
files/plugins/check_swap_activity (+78/-0)
hooks/nrpe_helpers.py (+6/-0)
tests/10-tests (+10/-0)
Reviewer Review Type Date Requested Status
NRPE charm developers Pending
Review via email: mp+328398@code.launchpad.net

Description of the change

Add swap_activity check and bump default swap usage limits to more accurately reflect actionable resource-starvation probable states.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/config.yaml b/config.yaml
index 680397c..1086205 100644
--- a/config.yaml
+++ b/config.yaml
@@ -78,9 +78,13 @@ options:
78 type: string78 type: string
79 description: Users check79 description: Users check
80 swap:80 swap:
81 default: "-w 90% -c 75%"81 default: "-w 40% -c 25%"
82 type: string82 type: string
83 description: Swap check83 description: Swap check
84 swap_activity:
85 default: "-i 5 -w 100 -c 500"
86 type: string
87 description: Swap activity check
84 mem:88 mem:
85 default: "-C -u -w 85 -c 90"89 default: "-C -u -w 85 -c 90"
86 type: string90 type: string
diff --git a/files/plugins/check_swap_activity b/files/plugins/check_swap_activity
87new file mode 10075591new file mode 100755
index 0000000..3fc49d4
--- /dev/null
+++ b/files/plugins/check_swap_activity
@@ -0,0 +1,78 @@
1#!/bin/bash
2
3# This script checks swap pageouts and reports number of kbytes moved
4# from physical ram to swap space in a given number of seconds
5#
6# Usage: "check_swap_activity -i interval -w warning_kbyts -c critical_kbytes
7#
8#
9
10set -eu
11
12. /usr/lib/nagios/plugins/utils.sh
13
14
15help() {
16cat << EOH
17usage: $0 [ -i ## ] -w ## -c ##
18
19Measures page-outs to swap over a given interval, by default 5 seconds.
20
21 -i time in seconds to monitor (defaults to 5 seconds)
22 -w warning Level in kbytes
23 -c critical Level in kbytes
24
25EOH
26}
27
28TIMEWORD=seconds
29WARN_LVL=
30CRIT_LVL=
31INTERVAL=5
32## FETCH ARGUMENTS
33while getopts "i:w:c:" OPTION; do
34 case "${OPTION}" in
35 i)
36 INTERVAL=${OPTARG}
37 if [ $INTERVAL -eq 1 ]; then
38 TIMEWORD=second
39 fi
40 ;;
41 w)
42 WARN_LVL=${OPTARG}
43 ;;
44 c)
45 CRIT_LVL=${OPTARG}
46 ;;
47 ?)
48 help
49 exit 3
50 ;;
51 esac
52done
53
54if [ -z ${WARN_LVL} ] || [ -z ${CRIT_LVL} ] ; then
55 help
56 exit 3
57fi
58
59## Get swap pageouts over $INTERVAL
60PAGEOUTS=$(vmstat -w ${INTERVAL} 2 | tail -n 1 | awk '{print $8}')
61
62SUMMARY="| swapout_size=${PAGEOUTS}KB;${WARN_LVL};${CRIT_LVL};"
63if [ ${PAGEOUTS} -lt ${WARN_LVL} ]; then
64 # pageouts are below threshold
65 echo "OK - ${PAGEOUTS} kb swapped out in last ${INTERVAL} ${TIMEWORD} $SUMMARY"
66 exit $STATE_OK
67elif [ ${PAGEOUTS} -ge ${CRIT_LVL} ]; then
68 ## SWAP IS IN CRITICAL STATE
69 echo "CRITICAL - ${PAGEOUTS} kb swapped out in last ${INTERVAL} ${TIMEWORD} $SUMMARY"
70 exit $STATE_CRITICAL
71elif [ ${PAGEOUTS} -ge ${WARN_LVL} ] && [ ${PAGEOUTS} -lt ${CRIT_LVL} ]; then
72 ## SWAP IS IN WARNING STATE
73 echo "WARNING - ${PAGEOUTS} kb swapped out in last ${INTERVAL} ${TIMEWORD} $SUMMARY"
74 exit $STATE_WARNING
75else
76 echo "CRITICAL: Failure to process pageout information $SUMMARY"
77 exit $STATE_UNKNOWN
78fi
diff --git a/hooks/nrpe_helpers.py b/hooks/nrpe_helpers.py
index 1b03b0f..6768e99 100644
--- a/hooks/nrpe_helpers.py
+++ b/hooks/nrpe_helpers.py
@@ -307,6 +307,12 @@ class SubordinateCheckDefinitions(dict):
307 'cmd_params': hookenv.config('swap'),307 'cmd_params': hookenv.config('swap'),
308 },308 },
309 {309 {
310 'description': 'Swap Activity',
311 'cmd_name': 'check_swap_activity',
312 'cmd_exec': local_plugin_dir + 'check_swap_activity',
313 'cmd_params': hookenv.config('swap_activity'),
314 },
315 {
310 'description': 'Memory',316 'description': 'Memory',
311 'cmd_name': 'check_mem',317 'cmd_name': 'check_mem',
312 'cmd_exec': local_plugin_dir + 'check_mem.pl',318 'cmd_exec': local_plugin_dir + 'check_mem.pl',
diff --git a/tests/10-tests b/tests/10-tests
index df455fa..29f2e58 100755
--- a/tests/10-tests
+++ b/tests/10-tests
@@ -71,6 +71,7 @@ class TestDeployment(unittest.TestCase):
71 'check_zombie_procs_sub',71 'check_zombie_procs_sub',
72 'check_total_procs_sub',72 'check_total_procs_sub',
73 'check_conntrack_sub',73 'check_conntrack_sub',
74 'check_swap_activity_sub',
74 ]75 ]
75 for check in checks:76 for check in checks:
76 if check not in monitors['monitors']['remote']['nrpe'].keys():77 if check not in monitors['monitors']['remote']['nrpe'].keys():
@@ -336,6 +337,15 @@ class TestDeployment(unittest.TestCase):
336 }337 }
337 self.check_nrpe_setting(**test_config)338 self.check_nrpe_setting(**test_config)
338339
340 def test_custom_swap_activity_check_params(self):
341 chk_key = 'command[check_swap_activity]=/usr/local/lib/nagios/plugins/check_swap_activity'
342 test_config = {
343 'filename': '/etc/nagios/nrpe.d/check_swap_activity_sub.cfg',
344 'expected_settings': {chk_key: '-w 20 -c 700'},
345 'juju_kv': {'swap_activity': '-w 20 -c 700'}
346 }
347 self.check_nrpe_setting(**test_config)
348
339 def test_custom_conntrack_check_params(self):349 def test_custom_conntrack_check_params(self):
340 chk_key = ('command[check_conntrack]=/usr/local/lib/nagios/plugins/'350 chk_key = ('command[check_conntrack]=/usr/local/lib/nagios/plugins/'
341 'check_conntrack.sh')351 'check_conntrack.sh')

Subscribers

People subscribed via source and target branches