Last active
August 18, 2017 13:37
-
-
Save shokoe/25040753bb847e7388d247f82cd1b7c4 to your computer and use it in GitHub Desktop.
Get tomcat 8 jdbc jmx info using jolokia from in app jdbc connectors (not tested with central connectors in tomcat)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# requires JSON.sh | |
# curl 'https://raw.githubusercontent.com/dominictarr/JSON.sh/master/JSON.sh' > /usr/local/bin/JSON.sh | |
# chmod 700 !$ | |
# requires jolokia at /opt/jolokia | |
# wget -O jolokia-jvm-1.3.7-agent.jar http://search.maven.org/remotecontent?filepath=org/jolokia/jolokia-jvm/1.3.7/jolokia-jvm-1.3.7-agent.jar | |
# mkdir /opt/jolokia | |
# mv jolokia-jvm-1.3.7-agent.jar /opt/jolokia | |
# requires jq | |
# apt-get install jq | |
T="./jdbc_jmx_$$.tmp" | |
P=`pgrep -f tomcat8` | |
su -s /bin/bash -c "java -jar /opt/jolokia/jolokia-jvm-1.3.7-agent.jar start $P" tomcat8 | |
if [ "x$1" = "xall" ]; then | |
A=`curl -s 'http://127.0.0.1:8778/jolokia/list' |\ | |
/usr/local/bin/JSON.sh -l -b |\ | |
egrep 'jdbc.*attr' | sed 's#.*attr","##; s#".*##' |\ | |
sort -u | egrep -v 'jmxName|loginTimeout|password' |\ | |
xargs | tr ' ' ',' | sed 's#,#","#g; s#^#"#; s#$#"#;'` | |
curl -s --data '{"type" : "read", "mbean" : "Catalina:class=javax.sql.DataSource,type=DataSource,*", "attribute" : ['$A']}' http://127.0.0.1:8778/jolokia/read | jq '.value' | |
else | |
curl -s --data '{"type" : "read", "mbean" : "Catalina:class=javax.sql.DataSource,*", "attribute" : ["numIdle","numActive","maxIdle","minIdle","initialSize","maxTotal"]}' http://127.0.0.1:8778/jolokia/read | jq '.value' | |
fi | |
su -s /bin/bash -c "java -jar /opt/jolokia/jolokia-jvm-1.3.7-agent.jar stop $P" tomcat8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment