This Unix/Linux script will count the number of Database connections from the application server to the Database.
This script is very useful to track and record the number of Database connections created by your application to investigate possible connection leaks and bursts.
Furthermore, this script can be used to understand your application DB connectivity behaviour and patterns.
Run this script on the application node and change the Database port DB_PORT:
#!/bin/ksh
export DB_PORT=1521
export INTERVAL=60
while [ true ]
do
echo "#--- $(date)" >> ./connections.log
netstat -an|grep ${DB_PORT} |wc -l >> ./connections.log
sleep ${INTERVAL}
done
Run the script in the background. The script will run the netstat command every 60 seconds. You can adjust the sleep interval.
Output example from the generated output connections.log showing an increasing connection count:
#--- Wed May 13 10:50:26 GMTDT 2019 130 #--- Wed May 13 10:51:26 GMTDT 2019 143 #--- Wed May 13 10:52:26 GMTDT 2019 150 #--- Wed May 13 10:53:26 GMTDT 2019 153
Further reading:
Leave a Reply