initial commit from code.google.com
This commit is contained in:
15
ec2-write-memory-metrics/README.txt
Normal file
15
ec2-write-memory-metrics/README.txt
Normal file
@@ -0,0 +1,15 @@
|
||||
# Introduction:
|
||||
ec2-write-memory-metrics was created to extend Amazon's default metrics for EC2 instances to include a metrics for memory usage.
|
||||
# Directions For Use:
|
||||
#
|
||||
ec2-write-memory-metrics.sh
|
||||
## Example of Use:
|
||||
#
|
||||
The most valuable use of this application is to be run through cron on a regular basis.
|
||||
#
|
||||
# Additional Information:
|
||||
#
|
||||
Author: Colin Johnson / colin@cloudavail.com
|
||||
Date: 2011-11-22
|
||||
Version 0.1
|
||||
License Type: GNU GENERAL PUBLIC LICENSE, Version 3
|
||||
18
ec2-write-memory-metrics/ec2-write-memory-metrics.sh
Normal file
18
ec2-write-memory-metrics/ec2-write-memory-metrics.sh
Normal file
@@ -0,0 +1,18 @@
|
||||
#!/bin/bash -
|
||||
#get instance id - used for putting metric
|
||||
INSTANCE_ID=`curl -s http://169.254.169.254/latest/meta-data/instance-id`
|
||||
INSTANCE_AZ=`curl -s curl http://169.254.169.254/latest/meta-data/placement/availability-zone/`
|
||||
INSTANCE_REGION=${INSTANCE_AZ%?}
|
||||
|
||||
#could be done using "free" or "vmstat" - use of less and grep is believed to provide widest compatibility - CJ 2011-11-24
|
||||
memfree=`cat /proc/meminfo | grep -i MemFree | grep -o [0-9]*`
|
||||
swaptotal=`cat /proc/meminfo | grep -i SwapTotal | grep -o [0-9]*`
|
||||
swapfree=`cat /proc/meminfo | grep -i SwapFree | grep -o [0-9]*`
|
||||
swapused=$(($swaptotal-$swapfree))
|
||||
|
||||
#mon-put-data to put metrics
|
||||
mon-put-data --region $INSTANCE_REGION --metric-name MemoryFree --namespace EC2/Memory --value $memfree --unit Kilobytes --dimensions "InstanceId=$INSTANCE_ID"
|
||||
mon-put-data --region $INSTANCE_REGION --metric-name SwapUsed --namespace EC2/Memory --value $swapused --unit Kilobytes --dimensions "InstanceId=$INSTANCE_ID"
|
||||
|
||||
#to run in cron every 5 minutes - note that you must first provide credentials for mon-put-data
|
||||
#echo "*/5 * * * * ec2-user /usr/local/bin/ec2-write-memory-metrics.sh" > /etc/cron.d/ec2-write-memory-metrics
|
||||
Reference in New Issue
Block a user