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
1diff --git a/config.yaml b/config.yaml
2index 680397c..1086205 100644
3--- a/config.yaml
4+++ b/config.yaml
5@@ -78,9 +78,13 @@ options:
6 type: string
7 description: Users check
8 swap:
9- default: "-w 90% -c 75%"
10+ default: "-w 40% -c 25%"
11 type: string
12 description: Swap check
13+ swap_activity:
14+ default: "-i 5 -w 100 -c 500"
15+ type: string
16+ description: Swap activity check
17 mem:
18 default: "-C -u -w 85 -c 90"
19 type: string
20diff --git a/files/plugins/check_swap_activity b/files/plugins/check_swap_activity
21new file mode 100755
22index 0000000..3fc49d4
23--- /dev/null
24+++ b/files/plugins/check_swap_activity
25@@ -0,0 +1,78 @@
26+#!/bin/bash
27+
28+# This script checks swap pageouts and reports number of kbytes moved
29+# from physical ram to swap space in a given number of seconds
30+#
31+# Usage: "check_swap_activity -i interval -w warning_kbyts -c critical_kbytes
32+#
33+#
34+
35+set -eu
36+
37+. /usr/lib/nagios/plugins/utils.sh
38+
39+
40+help() {
41+cat << EOH
42+usage: $0 [ -i ## ] -w ## -c ##
43+
44+Measures page-outs to swap over a given interval, by default 5 seconds.
45+
46+ -i time in seconds to monitor (defaults to 5 seconds)
47+ -w warning Level in kbytes
48+ -c critical Level in kbytes
49+
50+EOH
51+}
52+
53+TIMEWORD=seconds
54+WARN_LVL=
55+CRIT_LVL=
56+INTERVAL=5
57+## FETCH ARGUMENTS
58+while getopts "i:w:c:" OPTION; do
59+ case "${OPTION}" in
60+ i)
61+ INTERVAL=${OPTARG}
62+ if [ $INTERVAL -eq 1 ]; then
63+ TIMEWORD=second
64+ fi
65+ ;;
66+ w)
67+ WARN_LVL=${OPTARG}
68+ ;;
69+ c)
70+ CRIT_LVL=${OPTARG}
71+ ;;
72+ ?)
73+ help
74+ exit 3
75+ ;;
76+ esac
77+done
78+
79+if [ -z ${WARN_LVL} ] || [ -z ${CRIT_LVL} ] ; then
80+ help
81+ exit 3
82+fi
83+
84+## Get swap pageouts over $INTERVAL
85+PAGEOUTS=$(vmstat -w ${INTERVAL} 2 | tail -n 1 | awk '{print $8}')
86+
87+SUMMARY="| swapout_size=${PAGEOUTS}KB;${WARN_LVL};${CRIT_LVL};"
88+if [ ${PAGEOUTS} -lt ${WARN_LVL} ]; then
89+ # pageouts are below threshold
90+ echo "OK - ${PAGEOUTS} kb swapped out in last ${INTERVAL} ${TIMEWORD} $SUMMARY"
91+ exit $STATE_OK
92+elif [ ${PAGEOUTS} -ge ${CRIT_LVL} ]; then
93+ ## SWAP IS IN CRITICAL STATE
94+ echo "CRITICAL - ${PAGEOUTS} kb swapped out in last ${INTERVAL} ${TIMEWORD} $SUMMARY"
95+ exit $STATE_CRITICAL
96+elif [ ${PAGEOUTS} -ge ${WARN_LVL} ] && [ ${PAGEOUTS} -lt ${CRIT_LVL} ]; then
97+ ## SWAP IS IN WARNING STATE
98+ echo "WARNING - ${PAGEOUTS} kb swapped out in last ${INTERVAL} ${TIMEWORD} $SUMMARY"
99+ exit $STATE_WARNING
100+else
101+ echo "CRITICAL: Failure to process pageout information $SUMMARY"
102+ exit $STATE_UNKNOWN
103+fi
104diff --git a/hooks/nrpe_helpers.py b/hooks/nrpe_helpers.py
105index 1b03b0f..6768e99 100644
106--- a/hooks/nrpe_helpers.py
107+++ b/hooks/nrpe_helpers.py
108@@ -307,6 +307,12 @@ class SubordinateCheckDefinitions(dict):
109 'cmd_params': hookenv.config('swap'),
110 },
111 {
112+ 'description': 'Swap Activity',
113+ 'cmd_name': 'check_swap_activity',
114+ 'cmd_exec': local_plugin_dir + 'check_swap_activity',
115+ 'cmd_params': hookenv.config('swap_activity'),
116+ },
117+ {
118 'description': 'Memory',
119 'cmd_name': 'check_mem',
120 'cmd_exec': local_plugin_dir + 'check_mem.pl',
121diff --git a/tests/10-tests b/tests/10-tests
122index df455fa..29f2e58 100755
123--- a/tests/10-tests
124+++ b/tests/10-tests
125@@ -71,6 +71,7 @@ class TestDeployment(unittest.TestCase):
126 'check_zombie_procs_sub',
127 'check_total_procs_sub',
128 'check_conntrack_sub',
129+ 'check_swap_activity_sub',
130 ]
131 for check in checks:
132 if check not in monitors['monitors']['remote']['nrpe'].keys():
133@@ -336,6 +337,15 @@ class TestDeployment(unittest.TestCase):
134 }
135 self.check_nrpe_setting(**test_config)
136
137+ def test_custom_swap_activity_check_params(self):
138+ chk_key = 'command[check_swap_activity]=/usr/local/lib/nagios/plugins/check_swap_activity'
139+ test_config = {
140+ 'filename': '/etc/nagios/nrpe.d/check_swap_activity_sub.cfg',
141+ 'expected_settings': {chk_key: '-w 20 -c 700'},
142+ 'juju_kv': {'swap_activity': '-w 20 -c 700'}
143+ }
144+ self.check_nrpe_setting(**test_config)
145+
146 def test_custom_conntrack_check_params(self):
147 chk_key = ('command[check_conntrack]=/usr/local/lib/nagios/plugins/'
148 'check_conntrack.sh')

Subscribers

People subscribed via source and target branches