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

add activity counters

parent 9e8afc51
No related branches found
No related tags found
1 merge request!91add activity counters
...@@ -143,7 +143,7 @@ EOH ...@@ -143,7 +143,7 @@ EOH
# param string database query # param string database query
function renderCounters(){ function renderCounters(){
local _query; _query="$1" local _query; _query="$1"
local _out; _out=$( psql -c "${_query} 2>&1") || _queryFailed local _out; _out=$( psql -c "${_query} " 2>&1) || _queryFailed
local _iCounter; typeset -i _iCounter=0 local _iCounter; typeset -i _iCounter=0
local _header; _header=$( echo "${_out}" | head -1 | tr -d ' ') local _header; _header=$( echo "${_out}" | head -1 | tr -d ' ')
local _data; _data=$( echo "${_out}" | head -3 | tail -1 | tr -d ' ') local _data; _data=$( echo "${_out}" | head -3 | tail -1 | tr -d ' ')
...@@ -220,14 +220,20 @@ sMode=$(ph.getValueWithParam '' m "$@") ...@@ -220,14 +220,20 @@ sMode=$(ph.getValueWithParam '' m "$@")
case "${sMode}" in case "${sMode}" in
"activity") "activity")
_out=$( psql -c "select pid,usename,state,query,backend_type,backend_start from pg_stat_activity" ) || _queryFailed _out=$( psql -c "select backend_type,state,query from pg_stat_activity" 2>&1 ) || _queryFailed
typeset -i iQTotal; iQTotal=$( tail -1 <<< "$_out" | cut -f 1 -d ' ' | tr -d '(' ) typeset -i iQTotal; iQTotal=$( tail -1 <<< "$_out" | cut -f 1 -d ' ' | tr -d '(' )
typeset -i iQActive; iQActive=$( awk '{ print $5 }' <<< "$_out" | grep -c "active" ) typeset -i iQActive; iQActive=$( awk '{ print $4 }' <<< "$_out" | grep -c "active" )
typeset -i iQIdle; iQIdle=$( awk '{ print $4 }' <<< "$_out" | grep -c "idle" )
typeset -i iQFastpath; iQFastpath=$(awk '{ print $4 }' <<< "$_out" | grep -c "fastpath" )
typeset -i iQOther; iQOther=$iQTotal-$iQActive-$iQIdle-$iQFastpath
descr="Running total: $iQTotal ... active: $iQActive" descr="Running total: $iQTotal ... active: $iQActive idle: $iQIdle fastpath: $iQFastpath other: $iQOther"
out="${_out}${NL}" out=$( grep "^.[a-z]" <<< "${_out}" | cut -c 1-150 )
ph.perfadd "running-total" "${iQTotal}" ph.perfadd "running-total" "${iQTotal}"
ph.perfadd "running-active" "${iQActive}" ph.perfadd "running-active" "${iQActive}"
ph.perfadd "running-idle" "${iQIdle}"
ph.perfadd "running-fastpath" "${iQFastpath}"
ph.perfadd "running-other" "${iQOther}"
;; ;;
"conflicts") "conflicts")
descr="Detected conflicts (from pg_stat_database_conflicts)" descr="Detected conflicts (from pg_stat_database_conflicts)"
...@@ -267,7 +273,7 @@ case "${sMode}" in ...@@ -267,7 +273,7 @@ case "${sMode}" in
from pg_stat_database " from pg_stat_database "
;; ;;
"replication") "replication")
_out=$( psql -c "select * from pg_stat_replication" ) || _queryFailed _out=$( psql -c "select * from pg_stat_replication" 2>&1 ) || _queryFailed
if tail -1 <<< "$_out" | grep "(0 rows)" >/dev/null ; then if tail -1 <<< "$_out" | grep "(0 rows)" >/dev/null ; then
descr="No data in pg_stat_replication - this is no slave." descr="No data in pg_stat_replication - this is no slave."
out="" out=""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment