Created
December 2, 2012 15:02
-
-
Save josnidhin/4189227 to your computer and use it in GitHub Desktop.
AWS AMI instance memory static to Cloudwatch
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 | |
export AWS_CLOUDWATCH_HOME=/opt/aws/apitools/mon # cloudwatch command line tools | |
export AWS_CLOUDWATCH_URL=https://monitoring.amazonaws.com # cloudwatch end point | |
export PATH=$AWS_CLOUDWATCH_HOME/bin:$PATH | |
export JAVA_HOME=/usr/lib/jvm/jre | |
# cloudwatch credential | |
CLOUDWATCHCREDENTIAL=/root/aws-custom-monitor/cloudwatch_credential.txt | |
# set the region | |
REGION="ap-southeast-1" | |
# set the namespace | |
NAMESPACE="System/API" | |
# get ec2 instance id | |
INSTANCEID=`wget -q -O - http://169.254.169.254/latest/meta-data/instance-id` | |
MEMTOTAL=`free -m | grep 'Mem' | tr -s ' ' | cut -d ' ' -f 2` | |
MEMFREE=`free -m | grep 'buffers/cache' | tr -s ' ' | cut -d ' ' -f 4` | |
let "MEMUSED=100-MEMFREE*100/MEMTOTAL" | |
mon-put-data --metric-name "FreeMemoryMBytes" --namespace "$NAMESPACE" --dimensions "InstanceId=$INSTANCEID" --value "$MEMFREE" --unit "Megabytes" --aws-credential-file "$CLOUDWATCHCREDENTIAL" --region "$REGION" | |
mon-put-data --metric-name "UsedMemoryPercent" --namespace "$NAMESPACE" --dimensions "InstanceId=$INSTANCEID" --value "$MEMUSED" --unit "Percent" --aws-credential-file "$CLOUDWATCHCREDENTIAL" --region "$REGION" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment