Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion pg_monz/usr-local-bin/pgsql_server_funcs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ PARAM1="$5"

# Load the psql connection option parameters.
source $PGSHELL_CONFDIR/pgsql_funcs.conf
source $(dirname $0)/pgsql_version

TIMESTAMP_QUERY='extract(epoch from now())::int'
if [ "`echo ${PGMAJORVERSION} | awk -F. '{ printf "%2d%02d", $1, $2 }'`" -ge 906 ]; then
WAITING_COUNT_QUERY="select count(*) from pg_stat_activity where wait_event is not null"
else
WAITING_COUNT_QUERY="select count(*) from pg_stat_activity where waiting = 'true'"
fi

#===============================================================================
# MAIN SCRIPT
Expand All @@ -31,7 +37,7 @@ case "$APP_NAME" in
union all \
select '\"$HOST_NAME\"', 'psql.idle_tx_connections', $TIMESTAMP_QUERY, (select count(*) from pg_stat_activity where state = 'idle in transaction') \
union all \
select '\"$HOST_NAME\"', 'psql.locks_waiting', $TIMESTAMP_QUERY, (select count(*) from pg_stat_activity where waiting = 'true') \
select '\"$HOST_NAME\"', 'psql.locks_waiting', $TIMESTAMP_QUERY, (${WAITING_COUNT_QUERY}) \
union all \
select '\"$HOST_NAME\"', 'psql.server_maxcon', $TIMESTAMP_QUERY, (select setting::int from pg_settings where name = 'max_connections')" 2>&1
)
Expand Down
2 changes: 2 additions & 0 deletions pg_monz/usr-local-bin/pgsql_version
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PGVERSION=${PGVERSION:-`psql --version | awk 'NR==1 { print $3 }'`}
PGMAJORVERSION=`echo "$PGVERSION" | sed 's/^\([0-9]*\.[0-9]*\).*$/\1/'`