Forked from atushi/How_to_use_the_CloudWatch_API_about_getting_the_JVM_info_with_proxy.sh
Created
February 27, 2018 18:53
-
-
Save boldandbusted/3e4e8a84d9c8dd19dc4a749d6f77ac2f to your computer and use it in GitHub Desktop.
How to use the Cloud Watch API about getting the JVM info with proxy.
This file contains 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 | |
# setting for proxy | |
export EC2_JVM_ARGS="-Dhttp.proxySet=true -DproxyHost=YOURPROXYHOST -DproxyPort=YOURPROXYPORT" | |
export SERVICE_JVM_ARGS=${EC2_JVM_ARGS} | |
# setting for cloud watch | |
export AWS_CREDENTIAL_FILE=$AWS_CLOUDWATCH_HOME/credentials | |
export AWS_CLOUDWATCH_URL=https://monitoring.amazonaws.com | |
export PATH=$AWS_CLOUDWATCH_HOME/bin:$PATH | |
# get ec2 instance id | |
instanceid=`wget --no-proxy -q -O - http://169.254.169.254/latest/meta-data/instance-id` | |
# get JVM info | |
bootstrappid=`jps | grep 'Bootstrap' | tr -s ' ' | cut -d ' ' -f 1` | |
jstat=`jstat -gcutil $bootstrappid | tail -1 | tr -s ' ' | cut -c2-100` | |
# set each JVM values | |
survivor0=`echo $jstat|cut -d ' ' -f 1` | |
survivor1=`echo $jstat|cut -d ' ' -f 2` | |
eden=`echo $jstat|cut -d ' ' -f 3` | |
old=`echo $jstat|cut -d ' ' -f 4` | |
permanent=`echo $jstat|cut -d ' ' -f 5` | |
young=`echo $jstat|cut -d ' ' -f 6` | |
youngtime=`echo $jstat|cut -d ' ' -f 7` | |
fgc=`echo $jstat|cut -d ' ' -f 8` | |
fgctime=`echo $jstat|cut -d ' ' -f 9` | |
gct=`echo $jstat|cut -d ' ' -f 10` | |
# put the JVM info to the CloudWatch | |
mon-put-data --metric-name "Survivor0" --namespace "Java/Tomcat" --dimensions "InstanceId=$instanceid" --value "$survivor0"--unit "Percent" --region ap-southeast-1 | |
mon-put-data --metric-name "Survivor1" --namespace "Java/Tomcat" --dimensions "InstanceId=$instanceid" --value "$survivor1" --unit "Percent" --region ap-southeast-1 | |
mon-put-data --metric-name "Eden" --namespace "Java/Tomcat" --dimensions "InstanceId=$instanceid" --value "$eden" --unit "Percent" --region ap-southeast-1 | |
mon-put-data --metric-name "Old" --namespace "Java/Tomcat" --dimensions "InstanceId=$instanceid" --value "$old" --unit "Percent" --region ap-southeast-1 | |
mon-put-data --metric-name "Permanent" --namespace "Java/Tomcat" --dimensions "InstanceId=$instanceid" --value "$permanent" --unit "Percent" --region ap-southeast-1 | |
mon-put-data --metric-name "YoungGC" --namespace "Java/Tomcat" --dimensions "InstanceId=$instanceid" --value "$young" --unit "Count" --region ap-southeast-1 | |
mon-put-data --metric-name "YoungGCTime" --namespace "Java/Tomcat" --dimensions "InstanceId=$instanceid" --value "$youngtime" --unit "Seconds" --region ap-southeast-1 | |
mon-put-data --metric-name "FullGC" --namespace "Java/Tomcat" --dimensions "InstanceId=$instanceid" --value "$fgc" --unit "Count" --region ap-southeast-1 | |
mon-put-data --metric-name "FullGCTime" --namespace "Java/Tomcat" --dimensions "InstanceId=$instanceid" --value "$fgctime" --unit "Seconds" --region ap-southeast-1 | |
mon-put-data --metric-name "TotalGCTime" --namespace "Java/Tomcat" --dimensions "InstanceId=$instanceid" --value "$gct" --unit "Seconds" --region ap-southeast-1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment