Created
August 22, 2013 11:56
-
-
Save atushi/6306265 to your computer and use it in GitHub Desktop.
How to use the Cloud Watch API about getting the instance status 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` | |
# memory | |
mem_total=`free -m | grep 'Mem' | tr -s ' ' | cut -d ' ' -f 2` | |
mem_free=`free -m | grep 'buffers/cache' | tr -s ' ' | cut -d ' ' -f 4` | |
let "mem_used=mem_total-mem_free" | |
let "mem_used_percent=mem_used*100/mem_total" | |
# diskUsage | |
diskusage=$(df | grep 'xvde' | tr -s ' ' | cut -d ' ' -f 5 | cut -d '%' -f 1) | |
# loadaverage | |
loadaverage=$(uptime | sed -e "s@^.*load average: @@" | tr -s ' ' | cut -d ' ' -f 1 | cut -d ',' -f 1) | |
# put the JVM info to the CloudWatch | |
mon-put-data --metric-name "FreeMemoryMBytes" --namespace "Status" --dimensions "InstanceId=$instanceid" --value "$mem_free" --unit "Megabytes" --timestamp "$TimeStamp" --region ap-southeast-1 | |
mon-put-data --metric-name "UsedMemoryPercent" --namespace "Status" --dimensions "InstanceId=$instanceid" --value "$mem_used_percent.00" --unit "Percent" --timestamp "$TimeStamp" --region ap-southeast-1 | |
mon-put-data --metric-name "DiskUsage" --namespace "Status" --dimensions "InstanceId=$instanceid" --value "$diskusage.00" --unit "Percent" --timestamp "$TimeStamp" --region ap-southeast-1 | |
mon-put-data --metric-name "LoadAverage" --namespace "Status" --dimensions "InstanceId=$instanceid" --value "$loadaverage" --unit "Count" --timestamp "$TimeStamp" --region ap-southeast-1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment