From d54058595d6177d98aa8bf730af61b3cd08188c0 Mon Sep 17 00:00:00 2001 From: "Hahn Axel (hahn)" <axel.hahn@iml.unibe.ch> Date: Thu, 24 Jun 2021 15:37:28 +0200 Subject: [PATCH] mysql: check if query cache is enabled as a shared function --- check_mysqlserver | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/check_mysqlserver b/check_mysqlserver index f135b4d..5a9912d 100755 --- a/check_mysqlserver +++ b/check_mysqlserver @@ -12,13 +12,19 @@ # - execute check_mysqlserver -i # # ---------------------------------------------------------------------- +# +# for mysql query cache: +# https://www.techpaste.com/2013/01/query-cache-mysql-server/ +# +# ---------------------------------------------------------------------- # 2020-08-xx v0.0 <axel.hahn@iml.unibe.ch> -# 2021-06-08 v0.0 <axel.hahn@iml.unibe.ch> update HOME .. better implement a param and ENV var +# 2021-06-08 v0.1 <axel.hahn@iml.unibe.ch> update HOME .. better implement a param and ENV var +# 2021-06-24 v0.2 <axel.hahn@iml.unibe.ch> check if query cache is enabled as a shared function # ====================================================================== . `dirname $0`/inc_pluginfunctions -_version="0.1" +_version="0.2" # --- set HOME # HOME=/etc/icinga2-passive-client @@ -98,6 +104,7 @@ EOF fi } +# show usage function _usage(){ cat <<EOH ______________________________________________________________________ @@ -178,6 +185,13 @@ function _mysqlrenderdelta() { test -z $deltaUnit && deltaUnit="sec" _mysqlrendervar "$1" "$2" $deltaUnit $4 } + +# helper function for caching checks +# The function aborts the check +function _verify_cache(){ + _mysqlgetvar "have_query_cache" | grep "YES" >/dev/null || ph.abort "Query cache (have_query_cache) is not active" + _mysqlgetvar "query_cache_type" | grep "OFF" >/dev/null && ph.abort "Query cache (have_query_cache) is active but query_cache_type is OFF" +} # ---------------------------------------------------------------------- # MAIN # ---------------------------------------------------------------------- @@ -286,14 +300,14 @@ case "${sMode}" in "qcache-blocks") descr="query cache blocks" - _mysqlgetvar "have_query_cache" | grep "YES" >/dev/null || ph.abort "Query cache is not active" + _verify_cache _mysqlrendervar Qcache_total_blocks "Qcache_" _mysqlrendervar Qcache_free_blocks "Qcache_" ;; "qcache-queries") descr="query cache data" - _mysqlgetvar "have_query_cache" | grep "YES" >/dev/null || ph.abort "Query cache is not active" + _verify_cache _mysqlrendervar Qcache_queries_in_cache "Qcache_" _mysqlrenderdelta Qcache_not_cached "Qcache_" min float _mysqlrenderdelta Qcache_lowmem_prunes "Qcache_" min float @@ -301,7 +315,7 @@ case "${sMode}" in "qcache-hits") descr="query cache hits" - _mysqlgetvar "have_query_cache" | grep "YES" >/dev/null || ph.abort "Query cache is not active" + _verify_cache _mysqlrenderdelta Qcache_hits "Qcache_" min _mysqlrenderdelta Qcache_inserts "Qcache_" min _mysqlrenderdelta Qcache_not_cached "Qcache_" min -- GitLab