Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Commit

Permalink
monodb-pgsql-health.sh: fixed minor logic error
Browse files Browse the repository at this point in the history
  • Loading branch information
LobbyLobster committed Jun 24, 2024
1 parent 523a1b8 commit adf6cab
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions monodb/monodb-pgsql-health.sh
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ function check_active_connections() {
max_and_used=$(gitlab-psql -c "SELECT max_conn, used FROM (SELECT COUNT(*) used FROM pg_stat_activity) t1, (SELECT setting::int max_conn FROM pg_settings WHERE name='max_connections') t2;" | awk 'NR==3')
else
max_and_used=$(su - postgres -c "psql -c \"SELECT max_conn, used FROM (SELECT COUNT(*) used FROM pg_stat_activity) t1, (SELECT setting::int max_conn FROM pg_settings WHERE name='max_connections') t2;\"" | awk 'NR==3')

fi

file="/tmp/monodb-pgsql-health/last-connection-above-limit.txt"
Expand All @@ -241,14 +240,14 @@ function check_active_connections() {
fi

if eval "$(echo "$used_percentage $CONN_LIMIT_PERCENT" | awk '{if ($1 >= $2) print "true"; else print "false"}')"; then
alarm_check_down "active_conn" "Number of Active Connections is $used_conn ($used_percentage)% and Above $CONN_LIMIT_PERCENT%"
alarm_check_down "active_conn" "Number of Active Connections is $used_conn ($used_percentage%) and Above $CONN_LIMIT_PERCENT%"
print_colour "Number of Active Connections" "$used_conn ($used_percentage)% and Above $CONN_LIMIT_PERCENT%" "error"
difference=$(((${used_percentage%.*} - ${CONN_LIMIT_PERCENT%.*}) / 10))
if [[ $difference -ge $increase ]]; then
increase=$((difference + 1))
if [ -f "$file" ]; then
alarm "[PostgreSQL - $IDENTIFIER] [:red_circle:] Number of Active Connections has passed $((CONN_LIMIT_PERCENT + (increase * 10)))% - It is now $used_conn%"
alarm "[PostgreSQL - $IDENTIFIER] [:red_circle:] Number of Active Connections has passed $((CONN_LIMIT_PERCENT + (increase * 10)))% - It is now $used_conn ($used_percentage%)"
fi
increase=$((difference + 1))
fi
echo "$increase" >$file
else
Expand Down

0 comments on commit adf6cab

Please sign in to comment.