Skip to content
Snippets Groups Projects
Commit 6ed9bef2 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

update psql

parent a07c2727
No related branches found
No related tags found
1 merge request!856010 check pqsql
...@@ -16,8 +16,9 @@ ...@@ -16,8 +16,9 @@
# ====================================================================== # ======================================================================
. `dirname $0`/inc_pluginfunctions . $(dirname $0)/inc_pluginfunctions
_version="0.1" self_APPNAME=$( basename $0 | tr [:lower:] [:upper:] )
self_APPVERSION=0.1
# --- set HOME # --- set HOME
HOME=/etc/icinga2-passive-client HOME=/etc/icinga2-passive-client
...@@ -26,7 +27,6 @@ HOME=/etc/icinga2-passive-client ...@@ -26,7 +27,6 @@ HOME=/etc/icinga2-passive-client
# --- other vars... # --- other vars...
cfgfile=$HOME/.psql.conf cfgfile=$HOME/.psql.conf
myuser=icingamonitor myuser=icingamonitor
datafile=/tmp/psqlvars.out
# new line # new line
NL=" NL="
...@@ -80,7 +80,7 @@ function _install(){ ...@@ -80,7 +80,7 @@ function _install(){
echo "- creating config file $cfgfile ... " echo "- creating config file $cfgfile ... "
cat >$cfgfile <<EOF cat >$cfgfile <<EOF
# #
# generated on `date` # generated on $(date)
# #
export PGUSER=${myuser} export PGUSER=${myuser}
export PGPASSWORD=${mypw} export PGPASSWORD=${mypw}
...@@ -95,17 +95,20 @@ EOF ...@@ -95,17 +95,20 @@ EOF
} }
function _usage(){ function _usage(){
local _self=$( basename $0 )
cat <<EOH cat <<EOH
______________________________________________________________________ ______________________________________________________________________
CHECK POSTGRESQL SERVER :: v${_version} ${self_APPNAME} :: v${self_APPVERSION}
THIS IS AN PRE ALPHA VERSION - DO NOT USE THIS
(c) Institute for Medical Education - Univerity of Bern (c) Institute for Medical Education - Univerity of Bern
Licence: GNU GPL 3 Licence: GNU GPL 3
______________________________________________________________________ ______________________________________________________________________
USAGE: USAGE:
`basename $0` [OPTIONS] -m METHOD $_self [OPTIONS] -m METHOD
OPTIONS: OPTIONS:
-h this help -h this help
...@@ -114,76 +117,29 @@ OPTIONS: ...@@ -114,76 +117,29 @@ OPTIONS:
PARAMETERS: PARAMETERS:
-m method; valid methods are: -m method; valid methods are:
connections current/ max connections dbstat first implmenetation test
connects connects per min and aborted connections/ clients
commands current running statements insert, select, ...
qcache-blocks query cache blocks total vs free
qcache-queries cached / non cached queries; low memeory prunes
qcache-hits query cache efficiency: cached vs non cached and inserted
EXAMPLES: EXAMPLES:
`basename $0` -i $_self -i
`basename $0` -m commands $_self -m commands
EOH EOH
} }
function _mysqlreadvars(){
mysql -e "SHOW GLOBAL VARIABLES ;" --skip-column-names >$datafile
mysql -e "SHOW STATUS ;" --skip-column-names >>$datafile
}
function _mysqlgetvar() {
local sVarname=$1
lastvalue=`grep "^$sVarname[^_a-z]" ${datafile} | awk '{ print $2 }'`
echo $lastvalue
}
# get a value from mysql status output
# param string variable name
# param string prefix to remove from beginning of variable
# param (set) flag if it is a delta value
function _mysqlrendervar() {
local sVarname=$1
local sRemove=$2
local sDeltaUnit=$3
local sFloat=$4
# local iValue=`grep "^$sVarname[^_a-z]" ${datafile} | awk '{ print $2 }'`
local iValue=`_mysqlgetvar "$sVarname"`
if [ "$iValue" = "" ]; then
ph.abort "no value for ${sVarname}"
fi
# get label for perfdata
local sLabel=`echo ${sVarname} | sed "s#^${sRemove}##g"`
if [ ! -z $sDeltaUnit ]; then
local iSpeed=` ph.perfdeltaspeed "mysql-${sVarname}" ${iValue} $sDeltaUnit $sFloat`
out=$out`printf "%25s: %10s %s \n" "${sLabel}" "${iValue}" "... delta = ${iSpeed} per $sDeltaUnit${NL}"`
ph.perfadd "${sLabel}" "${iSpeed}"
lastvalue=$iSpeed
else
out=${out}`printf "%25s: %10s \n" "${sLabel}" "${iValue}${NL}"`
ph.perfadd "${sLabel}" "${iValue}"
lastvalue=$iValue
fi
}
function _mysqlrenderdelta() {
local deltaUnit=$3
test -z $deltaUnit && deltaUnit="sec"
_mysqlrendervar "$1" "$2" $deltaUnit $4
}
function renderCounts(){ function renderCounts(){
local _query="$1" local _query="$1"
local _out=$( psql -c "${_query}") local _out=$( psql -c "${_query}")
# out+=$( echo "DEBUG: _query=${_query}${NL}" ) # out+=$( echo "DEBUG: _query=${_query}${NL}" )
# echo "DEBUG: _out="; echo "${_out}" # echo "DEBUG: _out="; echo "${_out}"
typeset -i local _iCounter=0 local _iCounter=0
local _header=$( echo "${_out}" | head -1 | tr -d ' ') typeset -i _iCounter
local _data=$( echo "${_out}" | head -3 | tail -1 | tr -d ' ')
local _header
_header=$( echo "${_out}" | head -1 | tr -d ' ')
local _data
_data=$( echo "${_out}" | head -3 | tail -1 | tr -d ' ')
# echo "DEBUG: _header=${_header}" # echo "DEBUG: _header=${_header}"
IFS="|" IFS="|"
read -ra aCols <<< "$_header" read -ra aCols <<< "$_header"
...@@ -201,9 +157,9 @@ function renderCounts(){ ...@@ -201,9 +157,9 @@ function renderCounts(){
# MAIN # MAIN
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
bOptInstall=` ph.hasParamoption "i" "$@"` bOptInstall=$( ph.hasParamoption "i" "$@")
bOptUninstall=` ph.hasParamoption "u" "$@"` bOptUninstall=$( ph.hasParamoption "u" "$@")
bOptHelp=` ph.hasParamoption "h" "$@"` bOptHelp=$( ph.hasParamoption "h" "$@")
if [ $bOptHelp -eq 1 -o $# -lt 1 ]; then if [ $bOptHelp -eq 1 -o $# -lt 1 ]; then
_usage _usage
...@@ -249,12 +205,12 @@ fi ...@@ -249,12 +205,12 @@ fi
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
sMode=`ph.getValueWithParam '' m "$@"` sMode=$(ph.getValueWithParam '' m "$@")
case "${sMode}" in case "${sMode}" in
"dbstat") "dbstat")
descr="stat database" descr="statistics over all databases"
renderCounts "select \ renderCounts "select \
sum(xact_commit) as commit, \ sum(xact_commit) as commit, \
sum(xact_rollback) as rollback, \ sum(xact_rollback) as rollback, \
...@@ -266,67 +222,6 @@ case "${sMode}" in ...@@ -266,67 +222,6 @@ case "${sMode}" in
# psql -c "select * from pg_stat_activity " # psql -c "select * from pg_stat_activity "
# psql -c "select * from pg_stat_statements " -> av psql v11 # psql -c "select * from pg_stat_statements " -> av psql v11
;; ;;
"connections")
descr="current/ max connections"
_mysqlrendervar max_connections
typeset -i iMaxConn=$lastvalue
_mysqlrendervar Max_used_connections
typeset -i iMaxUsed=$lastvalue
typeset -i iMaxPercent=$iMaxUsed*100/$iMaxConn
out=$out" --> $iMaxPercent % ${NL}${NL}"
_mysqlrendervar Threads_connected
typeset -i iThreads=$lastvalue
typeset -i iUsage=$iThreads*100/$iMaxConn
out=$out" --> $iUsage % ${NL}${NL}"
if [ $iWarnLimit -gt 0 -a $iCriticalLimit -gt 0 ]; then
ph.setStatusByLimit $iUsage $iWarnLimit $iCriticalLimit
fi
_mysqlrendervar Questions
;;
"connects")
descr="connects per min and aborted connections/ clients"
_mysqlrenderdelta Connections "" min float
_mysqlrenderdelta Aborted_clients "" min float
_mysqlrenderdelta Aborted_connects "" min float
;;
"commands")
descr="currently executed commands"
_mysqlrendervar Com_delete "Com_"
_mysqlrendervar Com_insert "Com_"
_mysqlrendervar Com_replace "Com_"
_mysqlrendervar Com_select "Com_"
_mysqlrendervar Com_update "Com_"
;;
"qcache-blocks")
descr="query cache blocks"
_mysqlgetvar "have_query_cache" | grep "YES" >/dev/null || ph.abort "Query cache is not active"
_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"
_mysqlrendervar Qcache_queries_in_cache "Qcache_"
_mysqlrenderdelta Qcache_not_cached "Qcache_" min float
_mysqlrenderdelta Qcache_lowmem_prunes "Qcache_" min float
;;
"qcache-hits")
descr="query cache hits"
_mysqlgetvar "have_query_cache" | grep "YES" >/dev/null || ph.abort "Query cache is not active"
_mysqlrenderdelta Qcache_hits "Qcache_" min
_mysqlrenderdelta Qcache_inserts "Qcache_" min
_mysqlrenderdelta Qcache_not_cached "Qcache_" min
;;
*) *)
echo ERRROR: [${sMode}] is an INVALID mode echo ERRROR: [${sMode}] is an INVALID mode
...@@ -338,7 +233,6 @@ esac ...@@ -338,7 +233,6 @@ esac
ph.status "Pgsql $sMode :: $descr" ph.status "Pgsql $sMode :: $descr"
echo "$out" echo "$out"
rm -f $datafile
ph.exit ph.exit
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment