summaryrefslogtreecommitdiff
path: root/ctdb
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2015-07-20 16:08:13 +1000
committerAmitay Isaacs <amitay@samba.org>2015-08-29 17:06:25 +0200
commitab58c7abd9c49325c3cee1e7178d04a3034e57d8 (patch)
tree7d880ff719e2894593c527ddfb195f4b34a2b248 /ctdb
parentb27ff251aff6d7c5c59dbe9b1748b30587402aa3 (diff)
downloadsamba-ab58c7abd9c49325c3cee1e7178d04a3034e57d8.tar.gz
ctdb-scripts: Move system memory checking to 05.system
Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Diffstat (limited to 'ctdb')
-rwxr-xr-xctdb/config/events.d/00.ctdb43
-rw-r--r--ctdb/config/events.d/05.system41
-rw-r--r--ctdb/doc/ctdbd.conf.5.xml12
-rwxr-xr-xctdb/tests/eventscripts/05.system.monitor.011.sh (renamed from ctdb/tests/eventscripts/00.ctdb.monitor.001.sh)0
-rwxr-xr-xctdb/tests/eventscripts/05.system.monitor.012.sh (renamed from ctdb/tests/eventscripts/00.ctdb.monitor.002.sh)0
-rwxr-xr-xctdb/tests/eventscripts/05.system.monitor.013.sh (renamed from ctdb/tests/eventscripts/00.ctdb.monitor.003.sh)0
-rwxr-xr-xctdb/tests/eventscripts/05.system.monitor.014.sh (renamed from ctdb/tests/eventscripts/00.ctdb.monitor.004.sh)0
-rwxr-xr-xctdb/tests/eventscripts/05.system.monitor.015.sh (renamed from ctdb/tests/eventscripts/00.ctdb.monitor.005.sh)0
8 files changed, 43 insertions, 53 deletions
diff --git a/ctdb/config/events.d/00.ctdb b/ctdb/config/events.d/00.ctdb
index 0e25e501754..da7186fb61e 100755
--- a/ctdb/config/events.d/00.ctdb
+++ b/ctdb/config/events.d/00.ctdb
@@ -116,46 +116,6 @@ set_ctdb_variables ()
done
}
-monitor_system_memory ()
-{
- # If monitoring free memory then calculate how much there is
- if [ -n "$CTDB_MONITOR_FREE_MEMORY_WARN" -o \
- -n "$CTDB_MONITOR_FREE_MEMORY" ] ; then
- free_mem=$(free -m | awk '$2 == "buffers/cache:" { print $4 }')
- fi
-
- # Shutdown CTDB when memory is below the configured limit
- if [ -n "$CTDB_MONITOR_FREE_MEMORY" ] ; then
- if [ $free_mem -le $CTDB_MONITOR_FREE_MEMORY ] ; then
- echo "CRITICAL: OOM - ${free_mem}MB free <= ${CTDB_MONITOR_FREE_MEMORY}MB (CTDB threshold)"
- echo "CRITICAL: Shutting down CTDB!!!"
- get_proc "meminfo"
- ps auxfww
- set_proc "sysrq-trigger" "m"
- ctdb disable
- sleep 3
- ctdb shutdown
- fi
- fi
-
- # Warn when low on memory
- if [ -n "$CTDB_MONITOR_FREE_MEMORY_WARN" ] ; then
- if [ $free_mem -le $CTDB_MONITOR_FREE_MEMORY_WARN ] ; then
- echo "WARNING: free memory is low - ${free_mem}MB free <= ${CTDB_MONITOR_FREE_MEMORY_WARN}MB (CTDB threshold)"
- fi
- fi
-
- # We should never enter swap, so SwapTotal == SwapFree.
- if [ "$CTDB_CHECK_SWAP_IS_NOT_USED" = "yes" ] ; then
- set -- $(get_proc "meminfo" | awk '$1 ~ /Swap(Total|Free):/ { print $2 }')
- if [ "$1" != "$2" ] ; then
- echo We are swapping:
- get_proc "meminfo"
- ps auxfww
- fi
- fi
-}
-
############################################################
ctdb_check_args "$@"
@@ -187,9 +147,6 @@ case "$1" in
startup)
ctdb attach ctdb.tdb persistent
;;
- monitor)
- monitor_system_memory
- ;;
*)
ctdb_standard_event_handler "$@"
diff --git a/ctdb/config/events.d/05.system b/ctdb/config/events.d/05.system
index 749b60fa2cc..b6303c0a324 100644
--- a/ctdb/config/events.d/05.system
+++ b/ctdb/config/events.d/05.system
@@ -62,10 +62,51 @@ monitor_filesystem_usage ()
done
}
+monitor_memory_usage ()
+{
+ # If monitoring free memory then calculate how much there is
+ if [ -n "$CTDB_MONITOR_FREE_MEMORY_WARN" -o \
+ -n "$CTDB_MONITOR_FREE_MEMORY" ] ; then
+ free_mem=$(free -m | awk '$2 == "buffers/cache:" { print $4 }')
+ fi
+
+ # Shutdown CTDB when memory is below the configured limit
+ if [ -n "$CTDB_MONITOR_FREE_MEMORY" ] ; then
+ if [ $free_mem -le $CTDB_MONITOR_FREE_MEMORY ] ; then
+ echo "CRITICAL: OOM - ${free_mem}MB free <= ${CTDB_MONITOR_FREE_MEMORY}MB (CTDB threshold)"
+ echo "CRITICAL: Shutting down CTDB!!!"
+ get_proc "meminfo"
+ ps auxfww
+ set_proc "sysrq-trigger" "m"
+ ctdb disable
+ sleep 3
+ ctdb shutdown
+ fi
+ fi
+
+ # Warn when low on memory
+ if [ -n "$CTDB_MONITOR_FREE_MEMORY_WARN" ] ; then
+ if [ $free_mem -le $CTDB_MONITOR_FREE_MEMORY_WARN ] ; then
+ echo "WARNING: free memory is low - ${free_mem}MB free <= ${CTDB_MONITOR_FREE_MEMORY_WARN}MB (CTDB threshold)"
+ fi
+ fi
+
+ # We should never enter swap, so SwapTotal == SwapFree.
+ if [ "$CTDB_CHECK_SWAP_IS_NOT_USED" = "yes" ] ; then
+ set -- $(get_proc "meminfo" | awk '$1 ~ /Swap(Total|Free):/ { print $2 }')
+ if [ "$1" != "$2" ] ; then
+ echo We are swapping:
+ get_proc "meminfo"
+ ps auxfww
+ fi
+ fi
+}
+
case "$1" in
monitor)
monitor_filesystem_usage
+ monitor_memory_usage
;;
*)
diff --git a/ctdb/doc/ctdbd.conf.5.xml b/ctdb/doc/ctdbd.conf.5.xml
index 3d7ae42ea41..77f75c8bf21 100644
--- a/ctdb/doc/ctdbd.conf.5.xml
+++ b/ctdb/doc/ctdbd.conf.5.xml
@@ -1279,7 +1279,7 @@ CTDB_PER_IP_ROUTING_TABLE_ID_HIGH=9000
<para>
CTDB can experience seemingly random (performance and other)
- issues if system resources become too contrained. Options in
+ issues if system resources become too constrained. Options in
this section can be enabled to allow certain system resources to
be checked.
</para>
@@ -1288,12 +1288,11 @@ CTDB_PER_IP_ROUTING_TABLE_ID_HIGH=9000
<title>Eventscripts</title>
<simplelist>
- <member><filename>00.ctdb</filename></member>
<member><filename>05.system</filename></member>
</simplelist>
<para>
- Filesystem usage monitoring is in
+ Filesystem and memory usage monitoring is in
<filename>05.system</filename>. This eventscript is not
enabled by default. Use <command>ctdb
enablescript</command> to enable it.
@@ -1318,13 +1317,6 @@ CTDB_PER_IP_ROUTING_TABLE_ID_HIGH=9000
<para>
No default.
</para>
-
- <para>
- Note that this feature uses the
- <filename>05.system</filename> eventscript, which is not
- enabled by default. Use <command>ctdb
- enablescript</command> to enable it.
- </para>
</listitem>
</varlistentry>
diff --git a/ctdb/tests/eventscripts/00.ctdb.monitor.001.sh b/ctdb/tests/eventscripts/05.system.monitor.011.sh
index 4290d13e15d..4290d13e15d 100755
--- a/ctdb/tests/eventscripts/00.ctdb.monitor.001.sh
+++ b/ctdb/tests/eventscripts/05.system.monitor.011.sh
diff --git a/ctdb/tests/eventscripts/00.ctdb.monitor.002.sh b/ctdb/tests/eventscripts/05.system.monitor.012.sh
index 6e9401233b2..6e9401233b2 100755
--- a/ctdb/tests/eventscripts/00.ctdb.monitor.002.sh
+++ b/ctdb/tests/eventscripts/05.system.monitor.012.sh
diff --git a/ctdb/tests/eventscripts/00.ctdb.monitor.003.sh b/ctdb/tests/eventscripts/05.system.monitor.013.sh
index 9e63ab50fd3..9e63ab50fd3 100755
--- a/ctdb/tests/eventscripts/00.ctdb.monitor.003.sh
+++ b/ctdb/tests/eventscripts/05.system.monitor.013.sh
diff --git a/ctdb/tests/eventscripts/00.ctdb.monitor.004.sh b/ctdb/tests/eventscripts/05.system.monitor.014.sh
index fdf20329e2d..fdf20329e2d 100755
--- a/ctdb/tests/eventscripts/00.ctdb.monitor.004.sh
+++ b/ctdb/tests/eventscripts/05.system.monitor.014.sh
diff --git a/ctdb/tests/eventscripts/00.ctdb.monitor.005.sh b/ctdb/tests/eventscripts/05.system.monitor.015.sh
index a46851a573d..a46851a573d 100755
--- a/ctdb/tests/eventscripts/00.ctdb.monitor.005.sh
+++ b/ctdb/tests/eventscripts/05.system.monitor.015.sh