From ba77c317f8b8521a47b0064bd6e6a2fe09eb26e9 Mon Sep 17 00:00:00 2001 From: "Hahn Axel (hahn)" <axel.hahn@unibe.ch> Date: Fri, 9 Jun 2023 09:00:44 +0200 Subject: [PATCH] deltaunit can be set as parameter --- check_psqlserver | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/check_psqlserver b/check_psqlserver index b161b96..7ccf6e6 100755 --- a/check_psqlserver +++ b/check_psqlserver @@ -16,12 +16,13 @@ # 2023-06-07 v0.2 <axel.hahn@unibe.ch> # 2023-06-08 v0.3 <axel.hahn@unibe.ch> show unknown if database connection fails # 2023-06-08 v0.4 <axel.hahn@unibe.ch> get summary for cronflicts and problems +# 2023-06-09 v0.5 <axel.hahn@unibe.ch> deltaunit can be set as parameter # ====================================================================== . $(dirname $0)/inc_pluginfunctions self_APPNAME=$( basename $0 | tr [:lower:] [:upper:] ) -self_APPVERSION=0.2 +self_APPVERSION=0.5 # --- other vars... cfgfile=/etc/icingaclient/.psql.conf @@ -142,13 +143,15 @@ EOH # render incremental counters from integer results of a given sql query # global string out output of check # param string database query +# param string time unit; one of sec|min; default: sec function renderCounters(){ local _query; _query="$1" + local _sDeltaUnit; _sDeltaUnit=${2:-sec} + local _out; _out=$( psql -c "${_query} " 2>&1) || _queryFailed local _iCounter; typeset -i _iCounter=0 local _header; _header=$( echo "${_out}" | head -1 | tr -d ' ') local _data; _data=$( echo "${_out}" | head -3 | tail -1 | tr -d ' ') - local _sDeltaUnit; _sDeltaUnit=sec local _iSpeed; typeset -i _iSpeed=0 local _sStoreid; _sStoreid=$( md5sum <<< "${_query}" | awk '{ print $1 }' ) local _iValue; typeset -i _iValue @@ -238,6 +241,7 @@ case "${sMode}" in ;; "conflicts") + deltaunit=min descr="Detected conflicts (from pg_stat_database_conflicts)" renderCounters "select \ sum(confl_tablespace) as confl_tablespace, \ @@ -245,14 +249,14 @@ case "${sMode}" in sum(confl_snapshot) as confl_snapshot, \ sum(confl_bufferpin) as confl_bufferpin, \ sum(confl_deadlock) as confl_deadlock \ - from pg_stat_database_conflicts " + from pg_stat_database_conflicts " "${deltaunit}" # sum of 7th column (with delta per sec) typeset -i iTotal; iTotal=$( echo "$out" | awk '{ sum+=$7} END { print sum;}' ) if [ $iTotal -gt 0 ]; then ph.setStatus "warning" fi - descr+=" - currently $iTotal per sec" + descr+=" - currently $iTotal per ${deltaunit}" ;; "dbrows") @@ -275,6 +279,7 @@ case "${sMode}" in ;; "problems") + deltaunit=min descr="Problems and troublemakers (from pg_stat_database)" renderCounters "select \ sum(conflicts) as conflicts, \ @@ -282,14 +287,14 @@ case "${sMode}" in sum(checksum_failures) as checksumfailures, \ sum(temp_files) as temp_files, \ sum(temp_bytes) as temp_bytes \ - from pg_stat_database " + from pg_stat_database" "${deltaunit}" # sum of 7th column (with delta per sec) typeset -i iTotal; iTotal=$( echo "$out" | awk '{ sum+=$7} END { print sum;}' ) if [ $iTotal -gt 0 ]; then ph.setStatus "warning" fi - descr+=" - currently $iTotal per sec" + descr+=" - currently $iTotal per ${deltaunit}" ;; "replication") -- GitLab