Skip to content

Instantly share code, notes, and snippets.

@sebastianwebber
Last active September 16, 2018 02:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sebastianwebber/b8eae926e6c1ae8d6294 to your computer and use it in GitHub Desktop.
Save sebastianwebber/b8eae926e6c1ae8d6294 to your computer and use it in GitHub Desktop.
Lists datasources usage on JBoss AS 4,5 and 6 or JBoss EAP 5
#!/bin/bash
## lista_ds.sh
## Lists datasources usage on JBoss AS 4,5 and 6 or JBoss EAP 5
### SAMPLE OUTPUT:
### INSTANCIA | PORTA | DS | MaxConnectionsInUseCount | AvailableConnectionCount |
### ---------------------|----------|----------------------|---------------------------|---------------------------|
### jboss-server-1 | 1199 | OracleDS | 8 | 50 |
### jboss-server-1 | 1199 | JmsXA | 0 | 20 |
# JBOSS_HOME="${1}"
# if [ "${JBOSS_HOME}X" = "X" ]; then
# echo "Input JBoss installation dir (JBOSS_HOME)"
# exit 2
# fi
# TODO: find a way to don't use mlocate
echo Updating mlocate database...
echo
updatedb
clear
function print_line() {
echo '---------------------|----------|-------------------------------------|---------------------------|---------------------------|'
}
echo
printf '%-20s | %-8s | %-35s | %-25s | %-25s | \n' "INSTANCIA" "PORTA" "DS" "MaxConnectionsInUseCount" "AvailableConnectionCount"
print_line
bind_address=$(ifconfig eth0 | grep inet | egrep --color=auto 'inet end.: [0-9\.]{1,}' -o | cut -d ':' -f 2 | xargs echo)
for proc in $(netstat -ntpl | egrep ':[0-9]{2}80\s' | awk '{print $4"_"$NF}' | sort); do
pid=$(echo "${proc}" | cut -d '_' -f2 | cut -d '/' -f 1)
instance_name=$(ps --no-headers -o cmd ww ${pid} | egrep -o --color=auto '\-c [a-zA-Z0-9\-]{1,}' | awk '{print ($NF)}')
ds_list=$(locate '*ds.xml' | grep "${instance_name}" | egrep -v tmp\|hsqldb)
twiddle_port=$(netstat -ntpl | grep ${pid} | egrep [1-2]{2}99 | awk '{print $4}' | cut -d ':' -f 2);
jboss_bin=$(ps --no-headers -o cmd ww ${pid} | egrep -o 'classpath [\/a-zA-Z\.]{1,}' | awk '{print $NF}' | xargs dirname)
prop_file=$(locate jmx-console-users.properties | grep "${instance_name}")
if [ "${prop_file}X" = "X" ] || [ "${jboss_bin}X" = "X" ]; then
continue
fi
credentials_file=$( grep \= "${prop_file}" | tail -n 1)
twiddle_user=$(echo "${credentials_file}" | cut -d = -f 1 | xargs echo)
twiddle_password=$(echo "${credentials_file}" | cut -d = -f 2 | egrep -o '[a-zA-Z0-9\@]{1,}' | xargs echo)
# echo "pid: ${pid}"
# echo "instance_name: ${instance_name}"
# echo "twiddle_port: ${twiddle_port}"
# echo "twiddle_user: ${twiddle_user}"
# echo "twiddle_password: ${twiddle_password}"
for ds_file in ${ds_list[@]}; do
lista_ds=$(grep jndi-name ${ds_file} | awk '{print $NF}' | egrep -o '>[a-zA-Z0-9\_\/.-]{1,}' | tr -d '>');
for nome_ds in ${lista_ds[@]}; do
data_sources=$(${jboss_bin}/twiddle.sh -s "jnp://${bind_address}:${twiddle_port}" -u ${twiddle_user} -p "${twiddle_password}" get "jboss.jca:name=${nome_ds},service=ManagedConnectionPool" MaxConnectionsInUseCount AvailableConnectionCount | xargs echo);
max_conn=$(echo "${data_sources}" | egrep -o "MaxConnectionsInUseCount\=[0-9]{1,}" | cut -d \= -f 2)
avail_conn=$(echo "${data_sources}" | egrep -o "AvailableConnectionCount\=[0-9]{1,}" | cut -d \= -f 2)
printf '%-20s | %-8s | %-35s | %-25s | %-25s | \n' "${instance_name}" "${twiddle_port}" "${nome_ds}" "${max_conn}" "${avail_conn}"
done
done
print_line
done
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment