initial commit from code.google.com
This commit is contained in:
commit
52dcc5c58e
29
as-apply-alarms/README.txt
Normal file
29
as-apply-alarms/README.txt
Normal file
|
@ -0,0 +1,29 @@
|
|||
# Introduction:
|
||||
as-apply-alarms was created to easily apply alarms to anywhere from one to a number of Amazon Auto Scaling Groups. The tool applies alarms for CPU Utilization. as-apply-alarms will run "out of the box" however the intent is rather to provide a template (and the logic) for managing multiple Auto Scaling Group's alarms.
|
||||
# Directions For Use:
|
||||
#
|
||||
## Example of Use:
|
||||
#
|
||||
as-apply-alarms -d auto-scaling-group-name -t name-of-sns-topic
|
||||
-
|
||||
the above example would apply alarms to the Auto Scaling Group named <auto-scaling-group-name> and if any of these Alarms enter state "Alarm" would send a message to "name-of-topic."
|
||||
#
|
||||
## Required Parameters:
|
||||
#
|
||||
as-apply-alarms requires the following two arguments:
|
||||
-g <auto-scaling-group-name> - the name of the Auto Scaling Group for which you wish to apply alarms.
|
||||
-t <name-of-topic> - the name of the sns-topic where Alarms should be sent.
|
||||
#
|
||||
## Optional Parameters:
|
||||
#
|
||||
-a - pass the -a parameter to apply alarms to all Auto Scaling Groups.
|
||||
-r <region> - region that contains the Auto Scaling Group(s) where alarms should be applied
|
||||
-e <evaluation period> - set to the number of evaluation periods before an SNS topic is notified.
|
||||
-p <previewmode> - set to "true" to preview what alarms would be applied.
|
||||
#
|
||||
# Additional Information:
|
||||
#
|
||||
Author: Colin Johnson / colin@cloudavail.com
|
||||
Date: 2012-03-01
|
||||
Version 0.5
|
||||
License Type: GNU GENERAL PUBLIC LICENSE, Version 3
|
97
as-apply-alarms/as-apply-alarms.sh
Executable file
97
as-apply-alarms/as-apply-alarms.sh
Executable file
|
@ -0,0 +1,97 @@
|
|||
#!/bin/bash -
|
||||
# Author: Colin Johnson / colin@cloudavail.com
|
||||
# Date: 2012-02-28
|
||||
# Version 0.5
|
||||
# License Type: GNU GENERAL PUBLIC LICENSE, Version 3
|
||||
#
|
||||
#as-alarm-apply start
|
||||
#confirms that executables required for succesful script execution are available
|
||||
prerequisitecheck()
|
||||
{
|
||||
for prerequisite in basename cut grep as-describe-auto-scaling-groups mon-put-metric-alarm
|
||||
do
|
||||
#use of "hash" chosen as it is a shell builtin and will add programs to hash table, possibly speeding execution. Use of type also considered - open to suggestions.
|
||||
hash $prerequisite &> /dev/null
|
||||
if [[ $? == 1 ]] #has exits with exit status of 70, executable was not found
|
||||
then echo "In order to use `basename $0` the executable \"$prerequisite\" must be installed." 1>&2 ; exit 70
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
#calls prerequisitecheck function to ensure that all executables required for script execution are available
|
||||
prerequisitecheck
|
||||
|
||||
#sets defaults of as-apply-alarms
|
||||
region="us-east-1"
|
||||
|
||||
#handles options processing
|
||||
while getopts :g:r:t:p:e:a opt
|
||||
do
|
||||
case $opt in
|
||||
g) asgname="$OPTARG";;
|
||||
r) region="$OPTARG";;
|
||||
t) topicname="$OPTARG";;
|
||||
e) evaluationperiod="$OPTARG";;
|
||||
p) previewmode="$OPTARG";;
|
||||
a) allasg="true";;
|
||||
*) echo "Error with Options Input. Cause of failure is most likely that an unsupported parameter was passed or a parameter was passed without a corresponding option." 1>&2 ; exit 64;;
|
||||
esac
|
||||
done
|
||||
|
||||
#sets previewmode - will echo commands rather than performing work
|
||||
case $previewmode in
|
||||
true|True) previewmode="echo"; echo "Preview Mode is set to \"True.\"" ;;
|
||||
""|false|False) previewmode="";;
|
||||
*) echo "You specified \"$previewmode\" for Preview Mode. If specifying a Preview Mode you must specificy either \"true\" or \"false.\"" 1>&2 ; exit 64;;
|
||||
esac
|
||||
|
||||
# evaluationperiod validator - must be a number between 1 and 99
|
||||
case $evaluationperiod in
|
||||
"") evaluationperiod=1;;
|
||||
[1-99]) ;;
|
||||
*) echo "You specified \"$evaluationperiod\" for your evaluation period. If specifying an evaluation period you must specify a period between 1 and 99." 1>&2 ; exit 64;;
|
||||
esac
|
||||
|
||||
# region validator
|
||||
case $region in
|
||||
us-east-1|us-west-2|us-west-1|eu-west-1|ap-southeast-1|ap-northeast-1|sa-east-1) ;;
|
||||
*) echo "The \"$region\" region does not exist. You must specify a valid region (example: -r us-east-1 or -r us-west-2)." 1>&2 ; exit 64;;
|
||||
esac
|
||||
|
||||
# single asg validator - runs if applying to only one asg
|
||||
if [[ $allasg != "true" ]]
|
||||
then
|
||||
if [[ $asgname == "" ]]
|
||||
then echo "You did not specify an Auto Scaling Group. You must select an Auto Scaling Group to apply alarms to (example: as-apply-alarms.sh -g <autoscalinggroupname>) or you must select all Auto Scaling Groups (example: as-apply-alarms.sh -a)." 1>&2 ; exit 64
|
||||
fi
|
||||
if [[ `as-describe-auto-scaling-groups $asgname --region $region --max-records 1000 2> /dev/null` =~ .*AUTO-SCALING-GROUP.*$asgname ]]
|
||||
then echo "Auto Scaling Group $asgname has been found."
|
||||
else echo "The Auto Scaling Group \"$asgname\" does not exist. You must specify a valid Auto Scaling Group." 1>&2 ; exit 64
|
||||
fi
|
||||
fi
|
||||
|
||||
# multiple asg validator - runs if applying to all asgs
|
||||
if [[ $allasg == "true" ]]
|
||||
then
|
||||
if [[ $asgname != "" ]]
|
||||
then
|
||||
echo "You specified both \"All\" Auto Scaling Groups and the Auto Scaling Group \"$asgname\" to apply alarms to. You must specify either one particular Auto Scaling Group (-g <autoscalinggroup>) or all Auto Scaling Groups (-a) but not both." 1>&2 ; exit 64
|
||||
else
|
||||
echo "Alarms will be applied to all Auto Scaling Groups."
|
||||
fi
|
||||
fi
|
||||
|
||||
asglist=`as-describe-auto-scaling-groups $asgname --show-long --region $region --max-records 1000 | grep -i "AUTO-SCALING-GROUP" | cut -d ',' -f2`
|
||||
|
||||
#the below works - should confirm it is an array
|
||||
for asgin in $asglist
|
||||
do
|
||||
echo "Applying Alarms to the Auto Scaling Group named $asgin."
|
||||
|
||||
#to be used if any alarms are dependent on instance size
|
||||
# asglaunchconfig=`as-describe-auto-scaling-groups $asgname --show-long | cut -d ',' -f3`
|
||||
# asginstancetype=`as-describe-launch-configs $asglaunchconfig --show-long | cut -d ',' -f4`
|
||||
|
||||
$previewmode mon-put-metric-alarm --alarm-name $asgin-ASG-CPUUtilization-Critical --metric-name CPUUtilization --namespace AWS/EC2 --statistic Average --period 300 --threshold 90 --comparison-operator GreaterThanThreshold --dimensions AutoScalingGroupName=$asgin --evaluation-periods $evaluationperiod --unit Percent --alarm-actions $topicname --region $region
|
||||
|
||||
done
|
32
as-update-launch-config/README.txt
Normal file
32
as-update-launch-config/README.txt
Normal file
|
@ -0,0 +1,32 @@
|
|||
# Introduction:
|
||||
as-update-launch-config was created to easily modify the EC2 Instance Type of an Auto Scaling Group's Launch Configuration File. The most typical use case is to change the size of instance used by an Auto Scaling Group, although as-update-launch-config can also be used to update the storage type, user-data or AMI used by a Launch Config (and hence, an Auto Scaling Group).
|
||||
#
|
||||
# Directions For Use:
|
||||
#
|
||||
## Example of Use:
|
||||
#
|
||||
as-update-launch-config -a my-scaling-group -i m1.small -u /home/cjohnson/web-server-user-data.txt
|
||||
-
|
||||
the above example would modify the Auto Scaling Group "my-scaling-group" to use an m1.small EC2 Instance Type with the user-data available at /home/cjohnson/web-server-user-data.txt - note that this would also use an Amazon Linux AMI by default. The three parameters -a -i and -u are required for operation, as explained in the section "Required Parameters."
|
||||
#
|
||||
## Required Parameters:
|
||||
#
|
||||
as-update-launch-config requires the following three arguments:
|
||||
-a <auto-scaling-group-name> - the name of the Auto Scaling Group that you wish to modify.
|
||||
-i <instance-type> - the EC Instance Type you wish to switch use - for example -i m1.small would mean all future instances are launched as m1.small EC2 Instances.
|
||||
-u <user-data> - path to the user-data file that the Auto Scaling Group's Launch Configuration should use.
|
||||
#
|
||||
## Optional Parameters:
|
||||
#
|
||||
-b <bits> if you specify a t1.micro, m1.small, m1.medium or c1.medium EC2 Instance Type you must specify either a 32-bit or 64-bit platform. This parameter is valid only for the t1.micro, m1.small, m1.medium and c1.medium instance types.
|
||||
-p <region> - allows you specify the region in which your Auto Scaling Group and Launch Configuration are in.
|
||||
-p <preview> - set to "true" if you wish to preview output rather than execute. Useful for testing.
|
||||
-s <storage> - set to ebs if you wish to use an EBS backed AMI or s3 if you wish to use an s3 backed AMI. With no input, ebs is selected by default.
|
||||
-m <AMI> - allows you specify the AMI that you desire your Auto Scaling Group's Launch Configuration to use.
|
||||
#
|
||||
# Additional Information:
|
||||
#
|
||||
Author: Colin Johnson / colin@cloudavail.com
|
||||
Date: 2012-03-07
|
||||
Version 0.5
|
||||
License Type: GNU GENERAL PUBLIC LICENSE, Version 3
|
157
as-update-launch-config/as-update-launch-config.sh
Executable file
157
as-update-launch-config/as-update-launch-config.sh
Executable file
|
@ -0,0 +1,157 @@
|
|||
#!/bin/bash -
|
||||
# Author: Colin Johnson / colin@cloudavail.com
|
||||
# Date: 2012-02-27
|
||||
# Version 0.5
|
||||
# License Type: GNU GENERAL PUBLIC LICENSE, Version 3
|
||||
#
|
||||
#####
|
||||
#as-update-launch-config start
|
||||
|
||||
#gets an AMI from set of inputs
|
||||
getimageidcurl()
|
||||
{
|
||||
#get list of AMIs - format is region,bitdepth,storage,ami-id, -s is required to prevent curl from outputing progress meter to stderr
|
||||
amimap=`curl -s ${awsec2amimap}`
|
||||
#gets instanceid from downloaded file
|
||||
imageid=`echo "$amimap" | grep "$region,$bits,$storage" | cut -d ',' -f4`
|
||||
echo "AMI ID $imageid will be used for the new Launch Configuration. Note that as-update-launch-config uses Amazon Linux AMIs by default."
|
||||
}
|
||||
|
||||
#determines that the user provided AMI does, in fact, exit
|
||||
imageidvalidation()
|
||||
{
|
||||
#amivalid redirects stderr to stdout - if the user provided AMI does not exist, the if statement will exit as-update-launch-config.sh else it is assumed that the user provided AMI exists
|
||||
amivalid=`ec2-describe-images $imageid --region $region 2>&1`
|
||||
if [[ $amivalid =~ "Client.InvalidAMIID.NotFound" ]]
|
||||
then echo "The AMI ID $imageid could not be found. If you specify an AMI (-m) it must exist and be in the given region (-r). Note that region (-r defaults to \"us-east-1\" if not given." 1>&2 ; exit 64
|
||||
else echo "The user provided AMI \"$imageid\" will be used when updating the Launch Configuration for the Auto Scaling Group \"$asgroupname.\""
|
||||
fi
|
||||
}
|
||||
|
||||
#confirms that executables required for succesful script execution are available
|
||||
prerequisitecheck()
|
||||
{
|
||||
for prerequisite in basename cut curl date head grep as-update-auto-scaling-group as-describe-launch-configs as-describe-auto-scaling-groups ec2-describe-images
|
||||
do
|
||||
#use of "hash" chosen as it is a shell builtin and will add programs to hash table, possibly speeding execution. Use of type also considered - open to suggestions.
|
||||
hash $prerequisite &> /dev/null
|
||||
if [[ $? == 1 ]] #has exits with exit status of 70, executable was not found
|
||||
then echo "In order to use `basename $0`, the executable \"$prerequisite\" must be installed." 1>&2 ; exit 70
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
#calls prerequisitecheck function to ensure that all executables required for script execution are available
|
||||
prerequisitecheck
|
||||
|
||||
#sets as-update-launch-config Defaults
|
||||
awsec2amimap="http://s3.amazonaws.com/colinjohnson-cloudavailprd/aws-ec2-ami-map.txt"
|
||||
region="us-east-1"
|
||||
dateymd=`date +"%F"`
|
||||
|
||||
#handles options processing
|
||||
while getopts :a:i:u:b:s:p:r:m: opt
|
||||
do
|
||||
case $opt in
|
||||
a) asgroupname="$OPTARG";;
|
||||
i) instancetype="$OPTARG";;
|
||||
u) userdata="$OPTARG";;
|
||||
b) bits="$OPTARG";;
|
||||
s) storage="$OPTARG";;
|
||||
p) preview="$OPTARG";;
|
||||
r) region="$OPTARG";;
|
||||
m) imageid="$OPTARG";;
|
||||
*) echo "Error with Options Input. Cause of failure is most likely that an unsupported parameter was passed or a parameter was passed without a corresponding option." 1>&2 ; exit 64 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
#sets previewmode - will echo commands rather than performing work
|
||||
case $preview in
|
||||
true|True) previewmode="echo"; echo "Preview Mode is set to $preview" 1>&2 ;;
|
||||
""|false|False) previewmode="";;
|
||||
*) echo "You specified \"$preview\" for Preview Mode. If specifying a Preview Mode you must specific either \"true\" or \"false.\"" 1>&2 ; exit 64 ;;
|
||||
esac
|
||||
|
||||
# instance-type validator
|
||||
case $instancetype in
|
||||
t1.micro|m1.small|c1.medium|m1.medium) bits=$bits ;
|
||||
# bit depth validator for micro to medium instances - demands that input of bits for micro to medium size instances be 32 or 64 bit
|
||||
if [[ $bits -ne 32 && bits -ne 64 ]]
|
||||
then echo "You must specify either a 32-bit (-b 32) or 64-bit (-b 64) platform for the \"$instancetype\" EC2 Instance Type." 1>&2 ; exit 64
|
||||
fi ;;
|
||||
m1.large|m1.xlarge|m2.xlarge|m2.2xlarge|m2.4xlarge|c1.xlarge|cc1.4xlarge) bits=64;;
|
||||
"") echo "You did not specify an EC2 Instance Type. You must specify a valid EC2 Instance Type (example: -i m1.small or -i m1.large)." 1>&2 ; exit 64;;
|
||||
*) echo "The \"$instancetype\" EC2 Instance Type does not exist. You must specify a valid EC2 Instance Type (example: -i m1.small or -i m1.large)." 1>&2 ; exit 64;;
|
||||
esac
|
||||
|
||||
# user-data validator
|
||||
if [[ ! -f $userdata ]]
|
||||
then echo "The user-data file \"$userdata\" does not exist. You must specify a valid user-data file (example: -u /path/to/user-data.txt)." 1>&2 ; exit 64
|
||||
fi
|
||||
|
||||
# storage validator
|
||||
case $storage in
|
||||
ebs|EBS) storage=EBS;;
|
||||
s3|S3) storage=S3;;
|
||||
"") storage=EBS ;; # if no storage type is set - default to EBS
|
||||
*) echo "The \"$storage\" storage type does not exist. You must specify a valid storage type (either: -s ebs or -s s3)." 1>&2 ; exit 64;;
|
||||
esac
|
||||
|
||||
# region validator
|
||||
case $region in
|
||||
us-east-1|us-west-2|us-west-1|eu-west-1|ap-southeast-1|ap-northeast-1|sa-east-1) ;;
|
||||
*) echo "The \"$region\" region does not exist. You must specify a valid region (example: -r us-east-1 or -r us-west-2)." 1>&2 ; exit 64;;
|
||||
esac
|
||||
|
||||
# as-group-name validator - need to also include "command not found" if as-describe-auto-scaling-groups doesn't fire
|
||||
if [[ -z $asgroupname ]]
|
||||
then echo "You must specify an Auto Scaling Group name (example: -a asgname)." 1>&2 ; exit 64
|
||||
fi
|
||||
|
||||
#creates list of Auto Scaling Groups
|
||||
asgresult=`as-describe-auto-scaling-groups $asgroupname --show-long --region $region --max-records 1000`
|
||||
|
||||
#user response for Auto Scaling Group lookup - alerts user if Auto Scaling Group was not found.
|
||||
if [[ $asgresult = "No AutoScalingGroups found" ]]
|
||||
then echo "The Auto Scaling Group named \"$asgroupname\" does not exist. You must specify an Auto Scaling Group that exists." 1>&2 ; exit 64
|
||||
fi
|
||||
|
||||
#if $imageid has a length of non-zero call imageidvalidation else call getimageid.
|
||||
if [[ -n $imageid ]]
|
||||
then imageidvalidation
|
||||
else
|
||||
getimageidcurl
|
||||
fi
|
||||
|
||||
#gets current launch-config
|
||||
launch_config_current=`echo $asgresult | head -n 1 | cut -d ',' -f3`
|
||||
|
||||
aslcresult=`as-describe-launch-configs $launch_config_current --show-long --region $region --max-records 1000`
|
||||
launch_config_security_group=`echo $aslcresult | cut -d ',' -f9`
|
||||
launch_config_key=`echo $aslcresult | cut -d ',' -f5`
|
||||
|
||||
echo "The Auto Scaling Group \"$asgroupname\" uses the security group \"$launch_config_security_group\"." 1>&2
|
||||
echo "The Auto Scaling Group \"$asgroupname\" uses the key \"$launch_config_key.\"" 1>&2
|
||||
|
||||
#code below searches for unique identifier for launch-config - without a unique identifier, launch config creation would fail.
|
||||
unique_lc_name_found=0
|
||||
lc_uniq_id=1
|
||||
aslc_list=`as-describe-launch-configs --show-long --region $region --max-records 1000 | cut -d ',' -f2`
|
||||
while [[ $unique_lc_name_found < 1 ]]
|
||||
do
|
||||
#tests if launch-config name will be unique
|
||||
if [[ $aslc_list =~ "$asgroupname-$dateymd-id-$lc_uniq_id" ]]
|
||||
then lc_uniq_id=$((lc_uniq_id+1))
|
||||
else
|
||||
unique_lc_name_found=1 ; #for testing "Launch Condifuration Named: \"$asgroupname-$dateymd-id-$lc_uniq_id.\""
|
||||
fi
|
||||
done
|
||||
|
||||
launchconfig_new="$asgroupname-$dateymd-id-$lc_uniq_id"
|
||||
|
||||
echo "A new Launch Configuration named \"$launchconfig_new\" for Auto Scaling Group \"$asgroupname\" will be created using EC2 Instance Type \"$instancetype\" and AMI \"$imageid.\""
|
||||
#Create Launch Config
|
||||
$previewmode as-create-launch-config $launchconfig_new --image-id $imageid --instance-type $instancetype --region $region --group $launch_config_security_group --key $launch_config_key --user-data-file $userdata
|
||||
#
|
||||
#Update Auto Scaling Group
|
||||
$previewmode as-update-auto-scaling-group $asgroupname --region $region --launch-configuration $launchconfig_new
|
39
aws-missing-tools-resources/Maps/aws-ec2-ami-map.txt
Normal file
39
aws-missing-tools-resources/Maps/aws-ec2-ami-map.txt
Normal file
|
@ -0,0 +1,39 @@
|
|||
#Region
|
||||
#Format: region,region,...
|
||||
us-east-1,us-west-2,us-west-1,eu-west-1,ap-southeast-1,ap-northeast-1,sa-east-1
|
||||
#Format: Region,bitdepth,storage,amiid
|
||||
#us-east-1
|
||||
us-east-1,32,EBS,ami-ed65ba84
|
||||
us-east-1,64,EBS,ami-e565ba8c
|
||||
us-east-1,32,S3,ami-db65bab2
|
||||
us-east-1,64,S3,ami-f565ba9c
|
||||
#us-west-2
|
||||
us-west-2,32,EBS,ami-38c64a08
|
||||
us-west-2,64,EBS,ami-3ac64a0a
|
||||
us-west-2,32,S3,ami-36c64a06
|
||||
us-west-2,64,S3,ami-30c64a00
|
||||
#us-west-1
|
||||
us-west-1,32,EBS,ami-978cd4d2
|
||||
us-west-1,64,EBS,ami-e78cd4a2
|
||||
us-west-1,32,S3,ami-e58cd4a0
|
||||
us-west-1,64,S3,ami-d98cd49c
|
||||
#eu-west-1
|
||||
eu-west-1,32,EBS,ami-fd231b89
|
||||
eu-west-1,64,EBS,ami-f9231b8d
|
||||
eu-west-1,32,S3,ami-fb231b8f
|
||||
eu-west-1,64,S3,ami-ff231b8b
|
||||
#ap-southeast-1
|
||||
ap-southeast-1,32,EBS,ami-b83374ea
|
||||
ap-southeast-1,64,EBS,ami-be3374ec
|
||||
ap-southeast-1,32,S3,ami-b43374e6
|
||||
ap-southeast-1,64,S3,ami-b23374e0
|
||||
#ap-northeast-1
|
||||
ap-northeast-1,32,EBS,ami-087acb09
|
||||
ap-northeast-1,64,EBS,ami-e47acbe5
|
||||
ap-northeast-1,32,S3,ami-087bca09
|
||||
ap-northeast-1,64,S3,ami-047bca05
|
||||
#sa-east-1
|
||||
sa-east-1,32,EBS,ami-aa855bb7
|
||||
sa-east-1,64,EBS,ami-a6855bbb
|
||||
sa-east-1,32,S3,ami-a8855bb5
|
||||
sa-east-1,64,S3,ami-ae855bb3
|
200
aws-missing-tools-resources/Maps/aws-ec2-cost-map.txt
Normal file
200
aws-missing-tools-resources/Maps/aws-ec2-cost-map.txt
Normal file
|
@ -0,0 +1,200 @@
|
|||
#Region
|
||||
#Format: region,region,...
|
||||
us-east-1,us-west-2,us-west-1,eu-west-1,ap-southeast-1,ap-northeast-1,sa-east-1
|
||||
#Format: Region,InstanceType,OS,Cost
|
||||
#us-east-1, linux
|
||||
us-east-1,t1.micro,linux,0.02
|
||||
us-east-1,m1.small,linux,0.085
|
||||
us-east-1,m1.medium,linux,0.16
|
||||
us-east-1,c1.medium,linux,0.17
|
||||
us-east-1,m1.large,linux,0.34
|
||||
us-east-1,m2.xlarge,linux,0.50
|
||||
us-east-1,m1.xlarge,linux,0.68
|
||||
us-east-1,c1.xlarge,linux,0.68
|
||||
us-east-1,m2.2xlarge,linux,1.00
|
||||
us-east-1,m2.4xlarge,linux,2.00
|
||||
us-east-1,cc1.4xlarge,linux,1.30
|
||||
us-east-1,cc2.8xlarge,linux,2.40
|
||||
us-east-1,cg1.4xlarge,linux,2.10
|
||||
#us-east-1, windows
|
||||
us-east-1,t1.micro,windows,0.03
|
||||
us-east-1,m1.small,windows,0.12
|
||||
us-east-1,m1.medium,windows,0.23
|
||||
us-east-1,c1.medium,windows,0.29
|
||||
us-east-1,m1.large,windows,0.48
|
||||
us-east-1,m2.xlarge,windows,0.62
|
||||
us-east-1,m1.xlarge,windows,0.96
|
||||
us-east-1,c1.xlarge,windows,1.16
|
||||
us-east-1,m2.2xlarge,windows,1.24
|
||||
us-east-1,m2.4xlarge,windows,2.48
|
||||
us-east-1,cc1.4xlarge,windows,1.61
|
||||
us-east-1,cc2.8xlarge,windows,2.97
|
||||
us-east-1,cg1.4xlarge,windows,2.60
|
||||
#us-west-2, linux
|
||||
us-west-2,t1.micro,linux,0.02
|
||||
us-west-2,m1.small,linux,0.085
|
||||
us-west-2,m1.medium,linux,0.16
|
||||
us-west-2,c1.medium,linux,0.17
|
||||
us-west-2,m1.large,linux,0.34
|
||||
us-west-2,m2.xlarge,linux,0.50
|
||||
us-west-2,m1.xlarge,linux,0.68
|
||||
us-west-2,c1.xlarge,linux,0.68
|
||||
us-west-2,m2.2xlarge,linux,1.00
|
||||
us-west-2,m2.4xlarge,linux,2.00
|
||||
us-west-2,cc1.4xlarge,linux,NA
|
||||
us-west-2,cc2.8xlarge,linux,NA
|
||||
us-west-2,cg1.4xlarge,linux,NA
|
||||
#us-west-2, windows
|
||||
us-west-2,t1.micro,windows,0.03
|
||||
us-west-2,m1.small,windows,0.12
|
||||
us-west-2,m1.medium,windows,0.23
|
||||
us-west-2,c1.medium,windows,0.29
|
||||
us-west-2,m1.large,windows,0.48
|
||||
us-west-2,m2.xlarge,windows,0.62
|
||||
us-west-2,m1.xlarge,windows,0.96
|
||||
us-west-2,c1.xlarge,windows,1.16
|
||||
us-west-2,m2.2xlarge,windows,1.24
|
||||
us-west-2,m2.4xlarge,windows,2.48
|
||||
us-west-2,cc1.4xlarge,windows,NA
|
||||
us-west-2,cc2.8xlarge,windows,NA
|
||||
us-west-2,cg1.4xlarge,windows,NA
|
||||
#us-west-1, linux
|
||||
us-west-1,t1.micro,linux,0.025
|
||||
us-west-1,m1.small,linux,0.095
|
||||
us-west-1,m1.medium,linux,0.18
|
||||
us-west-1,c1.medium,linux,0.19
|
||||
us-west-1,m1.large,linux,0.38
|
||||
us-west-1,m2.xlarge,linux,0.57
|
||||
us-west-1,m1.xlarge,linux,0.76
|
||||
us-west-1,c1.xlarge,linux,0.76
|
||||
us-west-1,m2.2xlarge,linux,1.14
|
||||
us-west-1,m2.4xlarge,linux,2.28
|
||||
us-west-1,cc1.4xlarge,linux,NA
|
||||
us-west-1,cc2.8xlarge,linux,NA
|
||||
us-west-1,cg1.4xlarge,linux,NA
|
||||
#us-west-1, windows
|
||||
us-west-1,t1.micro,windows,0.035
|
||||
us-west-1,m1.small,windows,0.13
|
||||
us-west-1,m1.medium,windows,0.25
|
||||
us-west-1,c1.medium,windows,0.31
|
||||
us-west-1,m1.large,windows,0.52
|
||||
us-west-1,m2.xlarge,windows,0.69
|
||||
us-west-1,m1.xlarge,windows,1.04
|
||||
us-west-1,c1.xlarge,windows,1.24
|
||||
us-west-1,m2.2xlarge,windows,1.38
|
||||
us-west-1,m2.4xlarge,windows,2.76
|
||||
us-west-1,cc1.4xlarge,windows,NA
|
||||
us-west-1,cc2.8xlarge,windows,NA
|
||||
us-west-1,cg1.4xlarge,windows,NA
|
||||
#eu-west-1, linux
|
||||
eu-west-1,t1.micro,linux,0.025
|
||||
eu-west-1,m1.small,linux,0.09
|
||||
eu-west-1,m1.medium,linux,0.18
|
||||
eu-west-1,c1.medium,linux,0.186
|
||||
eu-west-1,m1.large,linux,0.38
|
||||
eu-west-1,m2.xlarge,linux,0.506
|
||||
eu-west-1,m1.xlarge,linux,0.72
|
||||
eu-west-1,c1.xlarge,linux,0.744
|
||||
eu-west-1,m2.2xlarge,linux,1.012
|
||||
eu-west-1,m2.4xlarge,linux,2.024
|
||||
eu-west-1,cc1.4xlarge,linux,NA
|
||||
eu-west-1,cc2.8xlarge,linux,NA
|
||||
eu-west-1,cg1.4xlarge,linux,NA
|
||||
#eu-west-1, windows
|
||||
eu-west-1,t1.micro,windows,0.035
|
||||
eu-west-1,m1.small,windows,0.115
|
||||
eu-west-1,m1.medium,windows,0.285
|
||||
eu-west-1,c1.medium,windows,0.285
|
||||
eu-west-1,m1.large,windows,0.46
|
||||
eu-west-1,m2.xlarge,windows,0.57
|
||||
eu-west-1,m1.xlarge,windows,0.92
|
||||
eu-west-1,c1.xlarge,windows,1.14
|
||||
eu-west-1,m2.2xlarge,windows,1.14
|
||||
eu-west-1,m2.4xlarge,windows,2.28
|
||||
eu-west-1,cc1.4xlarge,windows,NA
|
||||
eu-west-1,cc2.8xlarge,windows,NA
|
||||
eu-west-1,cg1.4xlarge,windows,NA
|
||||
#ap-southeast-1, linux
|
||||
ap-southeast-1,t1.micro,linux,0.025
|
||||
ap-southeast-1,m1.small,linux,0.095
|
||||
ap-southeast-1,m1.medium,linux,0.18
|
||||
ap-southeast-1,c1.medium,linux,0.19
|
||||
ap-southeast-1,m1.large,linux,0.38
|
||||
ap-southeast-1,m2.xlarge,linux,0.57
|
||||
ap-southeast-1,m1.xlarge,linux,0.76
|
||||
ap-southeast-1,c1.xlarge,linux,0.76
|
||||
ap-southeast-1,m2.2xlarge,linux,1.14
|
||||
ap-southeast-1,m2.4xlarge,linux,2.28
|
||||
ap-southeast-1,cc1.4xlarge,linux,NA
|
||||
ap-southeast-1,cc2.8xlarge,linux,NA
|
||||
ap-southeast-1,cg1.4xlarge,linux,NA
|
||||
#ap-southeast-1, windows
|
||||
ap-southeast-1,t1.micro,windows,0.035
|
||||
ap-southeast-1,m1.small,windows,0.12
|
||||
ap-southeast-1,m1.medium,windows,0.23
|
||||
ap-southeast-1,c1.medium,windows,0.29
|
||||
ap-southeast-1,m1.large,windows,0.48
|
||||
ap-southeast-1,m2.xlarge,windows,0.62
|
||||
ap-southeast-1,m1.xlarge,windows,0.96
|
||||
ap-southeast-1,c1.xlarge,windows,1.16
|
||||
ap-southeast-1,m2.2xlarge,windows,1.24
|
||||
ap-southeast-1,m2.4xlarge,windows,2.48
|
||||
ap-southeast-1,cc1.4xlarge,windows,NA
|
||||
ap-southeast-1,cc2.8xlarge,windows,NA
|
||||
ap-southeast-1,cg1.4xlarge,windows,NA
|
||||
#ap-northeast-1, linux
|
||||
ap-northeast-1,t1.micro,linux,0.027
|
||||
ap-northeast-1,m1.small,linux,0.10
|
||||
ap-northeast-1,m1.medium,linux,0.184
|
||||
ap-northeast-1,c1.medium,linux,0.20
|
||||
ap-northeast-1,m1.large,linux,0.40
|
||||
ap-northeast-1,m2.xlarge,linux,0.60
|
||||
ap-northeast-1,m1.xlarge,linux,0.80
|
||||
ap-northeast-1,c1.xlarge,linux,0.80
|
||||
ap-northeast-1,m2.2xlarge,linux,1.20
|
||||
ap-northeast-1,m2.4xlarge,linux,2.39
|
||||
ap-northeast-1,cc1.4xlarge,linux,NA
|
||||
ap-northeast-1,cc2.8xlarge,linux,NA
|
||||
ap-northeast-1,cg1.4xlarge,linux,NA
|
||||
#ap-northeast-1, windows
|
||||
ap-northeast-1,t1.micro,windows,0.035
|
||||
ap-northeast-1,m1.small,windows,0.12
|
||||
ap-northeast-1,m1.medium,windows,0.23
|
||||
ap-northeast-1,c1.medium,windows,0.29
|
||||
ap-northeast-1,m1.large,windows,0.48
|
||||
ap-northeast-1,m2.xlarge,windows,0.62
|
||||
ap-northeast-1,m1.xlarge,windows,0.96
|
||||
ap-northeast-1,c1.xlarge,windows,1.16
|
||||
ap-northeast-1,m2.2xlarge,windows,1.24
|
||||
ap-northeast-1,m2.4xlarge,windows,2.48
|
||||
ap-northeast-1,cc1.4xlarge,windows,NA
|
||||
ap-northeast-1,cc2.8xlarge,windows,NA
|
||||
ap-northeast-1,cg1.4xlarge,windows,NA
|
||||
#sa-east-1, linux
|
||||
sa-east-1,t1.micro,linux,0.027
|
||||
sa-east-1,m1.small,linux,0.115
|
||||
sa-east-1,m1.medium,linux,0.23
|
||||
sa-east-1,c1.medium,linux,0.23
|
||||
sa-east-1,m1.large,linux,0.46
|
||||
sa-east-1,m2.xlarge,linux,0.68
|
||||
sa-east-1,m1.xlarge,linux,0.92
|
||||
sa-east-1,c1.xlarge,linux,0.92
|
||||
sa-east-1,m2.2xlarge,linux,1.36
|
||||
sa-east-1,m2.4xlarge,linux,2.72
|
||||
sa-east-1,cc1.4xlarge,linux,NA
|
||||
sa-east-1,cc2.8xlarge,linux,NA
|
||||
sa-east-1,cg1.4xlarge,linux,NA
|
||||
#sa-east-1, windows
|
||||
sa-east-1,t1.micro,windows,0.037
|
||||
sa-east-1,m1.small,windows,0.15
|
||||
sa-east-1,m1.small,windows,0.30
|
||||
sa-east-1,c1.medium,windows,0.35
|
||||
sa-east-1,m1.large,windows,0.60
|
||||
sa-east-1,m2.xlarge,windows,0.80
|
||||
sa-east-1,m1.xlarge,windows,1.20
|
||||
sa-east-1,c1.xlarge,windows,1.40
|
||||
sa-east-1,m2.2xlarge,windows,1.60
|
||||
sa-east-1,m2.4xlarge,windows,3.20
|
||||
sa-east-1,cc1.4xlarge,windows,NA
|
||||
sa-east-1,cc2.8xlarge,windows,NA
|
||||
sa-east-1,cg1.4xlarge,windows,NA
|
|
@ -0,0 +1,47 @@
|
|||
Format:
|
||||
Test Procedure Name:
|
||||
Last Tested Date: <Date, in format YYYY-MM-DD>
|
||||
Last Tested Version: <Version Number>
|
||||
Result: <Pass/Fail>
|
||||
|
||||
1.1 ASG Selection:
|
||||
Last Tested Date: 2011-11-14
|
||||
Last Tested Version: 0.1
|
||||
Result: Pass
|
||||
Test with ASG set correctly. Applies alarms to selected RDS instance.
|
||||
Test with ASG set incorretly. Fails.
|
||||
Test with ASG set and ALLASG set. Fails.
|
||||
Test with ALLASG set. Applies alarms to all ASG resources.
|
||||
|
||||
1.2 Evaluation Period
|
||||
Last Tested Date: 2011-11-14
|
||||
Last Tested Version: 0.1
|
||||
Result: Pass
|
||||
Test with Evaluation Period not set.
|
||||
Test with Evaluation Period set to 1.
|
||||
Test with Evaluation Period set to 100.
|
||||
|
||||
1.3 SNS Topic Validator (Not implemented as of version 0.1)
|
||||
Last Tested Date: <Date>
|
||||
Last Tested Version: <Version Number>
|
||||
Result: <Pass/Fail>
|
||||
Test with SNS topic not set.
|
||||
Test with SNS topic set correctly.
|
||||
Test with SNS topic set incorrectly.
|
||||
|
||||
1.4 Preview Mode Validtor
|
||||
Last Tested Date: 2011-11-14
|
||||
Last Tested Version: 0.1
|
||||
Result: Pass
|
||||
Test with Previewmode not set. Result: alarms applied.
|
||||
Test with Previewmode set incorrectly. Result: exit.
|
||||
Test with Previewmode set to "True|true". Result: alarms applied.
|
||||
|
||||
1.5 ASG Availability (Not implemented as of version 0.1)
|
||||
Last Tested Date: <Date>
|
||||
Last Tested Version: <Version Number>
|
||||
Result: <Pass/Fail>
|
||||
Test -g with no asg resources available.
|
||||
Test -g with asg resources available.
|
||||
Test -a with no asg resources available.
|
||||
Test -a with asg resources available.
|
85
aws-missing-tools-resources/QA/as-apply-alarms/as-apply-alarms-Tests.sh
Executable file
85
aws-missing-tools-resources/QA/as-apply-alarms/as-apply-alarms-Tests.sh
Executable file
|
@ -0,0 +1,85 @@
|
|||
#!/bin/bash
|
||||
#sets path = to /dev/null
|
||||
AWS_MISSING_TOOLS_PATH="/Temp/aws-missing-tools/as-apply-alarms/"
|
||||
echo
|
||||
echo " -Test: Prerequisite Checking"
|
||||
echo " -Test: Prerequisite Fail"
|
||||
PATH_BAK=$PATH #backup of current path
|
||||
export PATH=/dev/null
|
||||
${AWS_MISSING_TOOLS_PATH}as-apply-alarms.sh
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Prerequisite Success"
|
||||
PATH=$PATH_BAK
|
||||
export PATH
|
||||
${AWS_MISSING_TOOLS_PATH}as-apply-alarms.sh
|
||||
echo "Exit Code: $?"
|
||||
|
||||
##### Region Test
|
||||
echo
|
||||
echo " -Test: Region Testing"
|
||||
echo " -Test: Calling without region."
|
||||
${AWS_MISSING_TOOLS_PATH}as-apply-alarms.sh -a
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling without a region option."
|
||||
${AWS_MISSING_TOOLS_PATH}as-apply-alarms.sh -r -a
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling with an invalid region option."
|
||||
${AWS_MISSING_TOOLS_PATH}as-apply-alarms.sh -r california
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling with a valid region option."
|
||||
${AWS_MISSING_TOOLS_PATH}as-apply-alarms.sh -r us-west-2
|
||||
echo "Exit Code: $?"
|
||||
|
||||
##### Evaluation Period Test
|
||||
echo
|
||||
echo " -Test: Evaluation Period Testing"
|
||||
echo " -Test: Calling without an Evaluation Period."
|
||||
${AWS_MISSING_TOOLS_PATH}as-apply-alarms.sh
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling without an Evaluation Period option."
|
||||
${AWS_MISSING_TOOLS_PATH}as-apply-alarms.sh -e
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling with an invalid (low) Evaluation Period option."
|
||||
${AWS_MISSING_TOOLS_PATH}as-apply-alarms.sh -e 0
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling with an invalid (high) Evaluation Period option."
|
||||
${AWS_MISSING_TOOLS_PATH}as-apply-alarms.sh -e 100
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling with a valid Evaluation Period option"
|
||||
${AWS_MISSING_TOOLS_PATH}as-apply-alarms.sh -e 1
|
||||
echo "Exit Code: $?"
|
||||
|
||||
##### ASG Tests
|
||||
echo
|
||||
echo " -Test: Auto Scaling Group Testing"
|
||||
echo " -Test: Calling without Auto Scaling Group."
|
||||
${AWS_MISSING_TOOLS_PATH}as-apply-alarms.sh
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling with no Auto Scaling Group defined."
|
||||
${AWS_MISSING_TOOLS_PATH}as-apply-alarms.sh -g
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling with an invalid Auto Scaling Group."
|
||||
${AWS_MISSING_TOOLS_PATH}as-apply-alarms.sh -g california
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling with an invalid Auto Scaling Group and all Auto Scaling Groups."
|
||||
${AWS_MISSING_TOOLS_PATH}as-apply-alarms.sh -g california -a
|
||||
echo "Exit Code: $?"
|
||||
as-create-launch-config amt-test-01 --image-id ami-31814f58 --instance-type t1.micro --key amt-test-01 --group amt-test-01
|
||||
as-create-auto-scaling-group amt-test-01 --min-size 0 --max-size 0 --desired-capacity 0 --launch-configuration amt-test-01 --availability-zones us-east-1a
|
||||
as-create-launch-config amt-test-02 --image-id ami-31814f58 --instance-type t1.micro --key amt-test-01 --group amt-test-01
|
||||
as-create-auto-scaling-group amt-test-02 --min-size 0 --max-size 0 --desired-capacity 0 --launch-configuration amt-test-02 --availability-zones us-east-1a
|
||||
echo " -Test: Calling with a valid Auto Scaling Group and all Auto Scaling Groups."
|
||||
${AWS_MISSING_TOOLS_PATH}as-apply-alarms.sh -g amt-test-01 -a
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling with a valid Auto Scaling Group."
|
||||
${AWS_MISSING_TOOLS_PATH}as-apply-alarms.sh -g amt-test-01
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling with all Auto Scaling Groups."
|
||||
${AWS_MISSING_TOOLS_PATH}as-apply-alarms.sh -a
|
||||
echo "Exit Code: $?"
|
||||
|
||||
as-delete-auto-scaling-group amt-test-01 -f
|
||||
as-delete-launch-config amt-test-01 -f
|
||||
as-delete-auto-scaling-group amt-test-02 -f
|
||||
as-delete-launch-config amt-test-02 -f
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
#!/bin/bash
|
||||
#sets path = to /dev/null
|
||||
AWS_MISSING_TOOLS_PATH=/Temp/aws-missing-tools/as-update-launch-config/
|
||||
echo
|
||||
echo " -Test: Prerequisite Checking"
|
||||
echo " -Test: Prerequisite Fail"
|
||||
PATH_BAK=$PATH #backup of current path
|
||||
export PATH=/dev/null
|
||||
${AWS_MISSING_TOOLS_PATH}as-update-launch-config.sh
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Prerequisite Success"
|
||||
PATH=$PATH_BAK
|
||||
export PATH
|
||||
${AWS_MISSING_TOOLS_PATH}as-update-launch-config.sh
|
||||
echo
|
||||
|
||||
##### Instance Type Test
|
||||
echo " -Test: Instance Type Testing"
|
||||
echo " -Test: Calling without an Instance Type"
|
||||
${AWS_MISSING_TOOLS_PATH}as-update-launch-config.sh
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling without an Instance Type"
|
||||
${AWS_MISSING_TOOLS_PATH}as-update-launch-config.sh -i
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling without an Invalid Instance Type"
|
||||
${AWS_MISSING_TOOLS_PATH}as-update-launch-config.sh -i m1.micro
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling with a Valid Instance Type:"
|
||||
${AWS_MISSING_TOOLS_PATH}as-update-launch-config.sh -i m1.small
|
||||
echo "Exit Code: $?"
|
||||
|
||||
##### User-Data Test
|
||||
echo
|
||||
echo " -Test: User-Data Testing"
|
||||
echo " -Test: Calling without user-data"
|
||||
${AWS_MISSING_TOOLS_PATH}as-update-launch-config.sh -i m1.small
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling without user-data option"
|
||||
${AWS_MISSING_TOOLS_PATH}as-update-launch-config.sh -i m1.small -u
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling with a valid user-data option"
|
||||
touch /Temp/touch.txt
|
||||
${AWS_MISSING_TOOLS_PATH}as-update-launch-config.sh -i m1.small -u /Temp/touch.txt
|
||||
echo "Exit Code: $?"
|
||||
|
||||
##### t1.micro test
|
||||
echo
|
||||
echo " -Test: t1.micro Bit Depth Testing"
|
||||
echo " -Test: Calling with a t1.micro instance type and no bit depth"
|
||||
${AWS_MISSING_TOOLS_PATH}as-update-launch-config.sh -i t1.micro
|
||||
echo "Exit Code: $?"
|
||||
echo
|
||||
echo " -Test: t1.micro Bit Depth Testing"
|
||||
echo " -Test: Calling with a t1.micro instance type and an empty bit depth"
|
||||
${AWS_MISSING_TOOLS_PATH}as-update-launch-config.sh -i t1.micro -b
|
||||
echo "Exit Code: $?"
|
||||
echo
|
||||
echo " -Test: t1.micro Bit Depth Testing"
|
||||
echo " -Test: Calling with a t1.micro instance type and 32 bit depth"
|
||||
${AWS_MISSING_TOOLS_PATH}as-update-launch-config.sh -i t1.micro -b 32
|
||||
echo "Exit Code: $?"
|
||||
echo
|
||||
echo " -Test: t1.micro Bit Depth Testing"
|
||||
echo " -Test: Calling with a t1.micro instance type and 64 bit depth"
|
||||
${AWS_MISSING_TOOLS_PATH}as-update-launch-config.sh -i t1.micro -b 64
|
||||
echo "Exit Code: $?"
|
||||
echo
|
||||
echo " -Test: t1.micro Bit Depth Testing"
|
||||
echo " -Test: Calling with a t1.micro instance type and 33 bit depth"
|
||||
${AWS_MISSING_TOOLS_PATH}as-update-launch-config.sh -i t1.micro -b 33
|
||||
echo "Exit Code: $?"
|
||||
|
||||
|
||||
##### Auto Scaling Group Test
|
||||
echo
|
||||
echo " -Test: Auto Scaling Group Testing"
|
||||
echo " -Test: Calling without an Auto Scaling Group"
|
||||
${AWS_MISSING_TOOLS_PATH}as-update-launch-config.sh -i m1.small -b 32 -u /Temp/touch.txt
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling without an Auto Scaling Group option."
|
||||
${AWS_MISSING_TOOLS_PATH}as-update-launch-config.sh -i m1.small -b 32 -u /Temp/touch.txt -a
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling with an invalid Auto Scaling Group"
|
||||
${AWS_MISSING_TOOLS_PATH}as-update-launch-config.sh -i m1.small -b 32 -u /Temp/touch.txt -a doesntexist
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling with a valid Auto Scaling Group"
|
||||
as-create-launch-config amt-test-01 --image-id ami-31814f58 --instance-type t1.micro --key amt-test-01 --group amt-test-01
|
||||
as-create-auto-scaling-group amt-test-01 --min-size 0 --max-size 0 --desired-capacity 0 --launch-configuration amt-test-01 --availability-zones us-east-1a
|
||||
${AWS_MISSING_TOOLS_PATH}as-update-launch-config.sh -i m1.small -b 32 -u /Temp/touch.txt -a amt-test-01
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling with a valid Auto Scaling Group and a Launch-Config amt-test-1 Already Created"
|
||||
${AWS_MISSING_TOOLS_PATH}as-update-launch-config.sh -i m1.small -b 32 -u /Temp/touch.txt -a amt-test-01
|
||||
echo "Exit Code: $?"
|
||||
as-delete-auto-scaling-group amt-test-01 -f
|
||||
as-delete-launch-config amt-test-01 -f
|
85
aws-missing-tools-resources/QA/asg-apply-alarms/asg-apply-alarms-Tests.sh
Executable file
85
aws-missing-tools-resources/QA/asg-apply-alarms/asg-apply-alarms-Tests.sh
Executable file
|
@ -0,0 +1,85 @@
|
|||
#!/bin/bash
|
||||
#sets path = to /dev/null
|
||||
AWS_MISSING_TOOLS_PATH="/Temp/aws-missing-tools/asg-apply-alarms/"
|
||||
echo
|
||||
echo " -Test: Prerequisite Checking"
|
||||
echo " -Test: Prerequisite Fail"
|
||||
PATH_BAK=$PATH #backup of current path
|
||||
export PATH=/dev/null
|
||||
${AWS_MISSING_TOOLS_PATH}asg-apply-alarms.sh
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Prerequisite Success"
|
||||
PATH=$PATH_BAK
|
||||
export PATH
|
||||
${AWS_MISSING_TOOLS_PATH}asg-apply-alarms.sh
|
||||
echo "Exit Code: $?"
|
||||
|
||||
##### Region Test
|
||||
echo
|
||||
echo " -Test: Region Testing"
|
||||
echo " -Test: Calling without region."
|
||||
${AWS_MISSING_TOOLS_PATH}asg-apply-alarms.sh -a
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling without a region option."
|
||||
${AWS_MISSING_TOOLS_PATH}asg-apply-alarms.sh -r -a
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling with an invalid region option."
|
||||
${AWS_MISSING_TOOLS_PATH}asg-apply-alarms.sh -r california
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling with a valid region option."
|
||||
${AWS_MISSING_TOOLS_PATH}asg-apply-alarms.sh -r us-west-2
|
||||
echo "Exit Code: $?"
|
||||
|
||||
##### Evaluation Period Test
|
||||
echo
|
||||
echo " -Test: Evaluation Period Testing"
|
||||
echo " -Test: Calling without an Evaluation Period."
|
||||
${AWS_MISSING_TOOLS_PATH}asg-apply-alarms.sh
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling without an Evaludation Period option."
|
||||
${AWS_MISSING_TOOLS_PATH}asg-apply-alarms.sh -e
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling with an invalid (low) Evaluation Period option."
|
||||
${AWS_MISSING_TOOLS_PATH}asg-apply-alarms.sh -e 0
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling with an invalid (high) Evaluation Period option."
|
||||
${AWS_MISSING_TOOLS_PATH}asg-apply-alarms.sh -e 100
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling with a valid Evaluation Period option"
|
||||
${AWS_MISSING_TOOLS_PATH}asg-apply-alarms.sh -e 1
|
||||
echo "Exit Code: $?"
|
||||
|
||||
##### ASG Tests
|
||||
echo
|
||||
echo " -Test: Auto Scaling Group Testing"
|
||||
echo " -Test: Calling without an Auto Scaling Group."
|
||||
${AWS_MISSING_TOOLS_PATH}asg-apply-alarms.sh
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling with no Auto Scaling Group defined."
|
||||
${AWS_MISSING_TOOLS_PATH}asg-apply-alarms.sh -g
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling with an invalid Auto Scaling Group."
|
||||
${AWS_MISSING_TOOLS_PATH}asg-apply-alarms.sh -g california
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling with an invalid Auto Scaling Group and all Auto Scaling Groups."
|
||||
${AWS_MISSING_TOOLS_PATH}asg-apply-alarms.sh -g california -a
|
||||
echo "Exit Code: $?"
|
||||
as-create-launch-config amt-test-01 --image-id ami-31814f58 --instance-type t1.micro --key amt-test-01 --group amt-test-01
|
||||
as-create-auto-scaling-group amt-test-01 --min-size 0 --max-size 0 --desired-capacity 0 --launch-configuration amt-test-01 --availability-zones us-east-1a
|
||||
as-create-launch-config amt-test-02 --image-id ami-31814f58 --instance-type t1.micro --key amt-test-01 --group amt-test-01
|
||||
as-create-auto-scaling-group amt-test-02 --min-size 0 --max-size 0 --desired-capacity 0 --launch-configuration amt-test-02 --availability-zones us-east-1a
|
||||
echo " -Test: Calling with a valid Auto Scaling Group and all Auto Scaling Groups."
|
||||
${AWS_MISSING_TOOLS_PATH}asg-apply-alarms.sh -g amt-test-01 -a
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling with a valid Auto Scaling Group."
|
||||
${AWS_MISSING_TOOLS_PATH}asg-apply-alarms.sh -g amt-test-01
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling with all Auto Scaling Groups."
|
||||
${AWS_MISSING_TOOLS_PATH}asg-apply-alarms.sh -a
|
||||
echo "Exit Code: $?"
|
||||
|
||||
as-delete-auto-scaling-group amt-test-01 -f
|
||||
as-delete-launch-config amt-test-01 -f
|
||||
as-delete-auto-scaling-group amt-test-02 -f
|
||||
as-delete-launch-config amt-test-02 -f
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
#!/bin/bash
|
||||
#set EC2CC_RB_APPLICATION prior to running
|
||||
EC2CC_RB_APPLICATION=/Temp/aws-missing-tools/ec2-cost-calculate-rb/ec2-cost-calculate.rb
|
||||
echo
|
||||
echo " -Test: Credentials File Checking"
|
||||
echo " -Test: Condition - Prerequisite File Does Not Exist"
|
||||
AWS_CREDENTIAL_FILE_BAK=$AWS_CREDENTIAL_FILE #backup of credential location
|
||||
export AWS_CREDENTIAL_FILE=/var/tmp/nofile.txt
|
||||
$EC2CC_RB_APPLICATION
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test Condition: Prerequisite Success"
|
||||
export AWS_CREDENTIAL_FILE=$AWS_CREDENTIAL_FILE_BAK
|
||||
$EC2CC_RB_APPLICATION
|
||||
echo
|
||||
|
||||
##### Simple Run Test
|
||||
echo " -Test: Simple Execution"
|
||||
$EC2CC_RB_APPLICATION
|
||||
echo "Exit Code: $?"
|
||||
##### Invalid Options Provided
|
||||
$EC2CC_RB_APPLICATION --option
|
||||
echo "Exit Code: $?"
|
||||
##### Invalid Options Provided
|
||||
$EC2CC_RB_APPLICATION --option invalid
|
||||
echo "Exit Code: $?"
|
||||
echo
|
||||
echo " -Test: Status Checking - Status Running"
|
||||
$EC2CC_RB_APPLICATION --status running
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Status Checking - Status All"
|
||||
$EC2CC_RB_APPLICATION --status all
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Status Checking - Status Invalid"
|
||||
$EC2CC_RB_APPLICATION --status invalid
|
||||
echo "Exit Code: $?"
|
||||
echo
|
||||
echo " -Test: Region Checking - Region us-east-1"
|
||||
$EC2CC_RB_APPLICATION --region us-east-1
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Region Checking - Region all"
|
||||
$EC2CC_RB_APPLICATION --region all
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Region Checking - Region invalid"
|
||||
$EC2CC_RB_APPLICATION --region invalid
|
||||
echo "Exit Code: $?"
|
||||
echo
|
||||
echo " -Test: Output Checking - Output Screen"
|
||||
$EC2CC_RB_APPLICATION --output screen
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Output Checking - Output File"
|
||||
echo " -Test: Output Checking - Output File Exists"
|
||||
$EC2CC_RB_APPLICATION --output file
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Output Checking - Output File Doesn't Exist, Custom Location"
|
||||
$EC2CC_RB_APPLICATION --output file --file ~/ec2cc_ooutput.txt
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Output Checking - Output File Exists, Custom Location"
|
||||
$EC2CC_RB_APPLICATION --output file file ~/ec2cc_ooutput.txt
|
||||
echo "Exit Code: $?"
|
||||
echo
|
||||
echo " -Test: Period Checking - Period Day"
|
||||
$EC2CC_RB_APPLICATION --period day
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Period Checking - Period Invalid"
|
||||
$EC2CC_RB_APPLICATION --period invalid
|
||||
echo "Exit Code: $?"
|
||||
echo
|
||||
echo " -Test: Seperator Checking - Seperator ;"
|
||||
$EC2CC_RB_APPLICATION --seperator \;
|
||||
echo "Exit Code: $?"
|
78
aws-missing-tools-resources/QA/rds-apply-alarms/rds-apply-alarms-Tests.sh
Executable file
78
aws-missing-tools-resources/QA/rds-apply-alarms/rds-apply-alarms-Tests.sh
Executable file
|
@ -0,0 +1,78 @@
|
|||
#!/bin/bash
|
||||
#sets path = to /dev/null
|
||||
AWS_MISSING_TOOLS_PATH="/Temp/aws-missing-tools/rds-apply-alarms/"
|
||||
echo
|
||||
echo " -Test: Prerequisite Checking"
|
||||
echo " -Test: Prerequisite Fail"
|
||||
PATH_BAK=$PATH #backup of current path
|
||||
export PATH=/dev/null
|
||||
${AWS_MISSING_TOOLS_PATH}rds-apply-alarms.sh
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Prerequisite Success"
|
||||
PATH=$PATH_BAK
|
||||
export PATH
|
||||
${AWS_MISSING_TOOLS_PATH}rds-apply-alarms.sh
|
||||
echo "Exit Code: $?"
|
||||
|
||||
##### Region Test
|
||||
echo
|
||||
echo " -Test: Region Testing"
|
||||
echo " -Test: Calling without region."
|
||||
${AWS_MISSING_TOOLS_PATH}rds-apply-alarms.sh -a
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling without a region option."
|
||||
${AWS_MISSING_TOOLS_PATH}rds-apply-alarms.sh -r -a
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling with an invalid region option."
|
||||
${AWS_MISSING_TOOLS_PATH}rds-apply-alarms.sh -r california
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling with a valid region option."
|
||||
${AWS_MISSING_TOOLS_PATH}rds-apply-alarms.sh -r us-west-2
|
||||
echo "Exit Code: $?"
|
||||
|
||||
##### Evaluation Period Test
|
||||
echo
|
||||
echo " -Test: Evaluation Period Testing"
|
||||
echo " -Test: Calling without an Evaluation Period."
|
||||
${AWS_MISSING_TOOLS_PATH}rds-apply-alarms.sh
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling without an Evaludation Period option."
|
||||
${AWS_MISSING_TOOLS_PATH}rds-apply-alarms.sh -e
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling with an invalid (low) Evaluation Period option."
|
||||
${AWS_MISSING_TOOLS_PATH}rds-apply-alarms.sh -e 0
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling with an invalid (high) Evaluation Period option."
|
||||
${AWS_MISSING_TOOLS_PATH}rds-apply-alarms.sh -e 100
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling with a valid Evaluation Period option"
|
||||
${AWS_MISSING_TOOLS_PATH}rds-apply-alarms.sh -e 1
|
||||
echo "Exit Code: $?"
|
||||
|
||||
##### RDS Instance Tests
|
||||
echo
|
||||
echo " -Test: RDS Instance Testing"
|
||||
echo " -Test: Calling without an RDS Instance."
|
||||
${AWS_MISSING_TOOLS_PATH}rds-apply-alarms.sh
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling with no RDS Instance option defined."
|
||||
${AWS_MISSING_TOOLS_PATH}rds-apply-alarms.sh -d
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling with an invalid RDS Instance Group."
|
||||
${AWS_MISSING_TOOLS_PATH}rds-apply-alarms.sh -d california
|
||||
echo "Exit Code: $?"
|
||||
rds-create-db-instance amt-test-01 --allocated-storage 5 --db-instance-class db.m1.small --engine mysql --master-user-password mj21s77 --master-username amttest01
|
||||
sleep 300
|
||||
echo " -Test: Calling with an invalid RDS Instance and all RDS Instances."
|
||||
${AWS_MISSING_TOOLS_PATH}rds-apply-alarms.sh -d california -a
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling with a valid RDS Instance and all RDS Instances."
|
||||
${AWS_MISSING_TOOLS_PATH}rds-apply-alarms.sh -d amt-test-1 -a
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling with a valid RDS Instance."
|
||||
${AWS_MISSING_TOOLS_PATH}rds-apply-alarms.sh -d amt-test-01
|
||||
echo "Exit Code: $?"
|
||||
echo " -Test: Calling with all RDS Instances."
|
||||
${AWS_MISSING_TOOLS_PATH}rds-apply-alarms.sh -a
|
||||
echo "Exit Code: $?"
|
||||
rds-delete-db-instance amt-test-01 -f --skip-final-snapshot
|
21
ec2-cost-calculate-ruby/README.txt
Normal file
21
ec2-cost-calculate-ruby/README.txt
Normal file
|
@ -0,0 +1,21 @@
|
|||
# Introduction:
|
||||
ec2-cost-calculate.rb was created to easily sum the total of instances running in one or all regions. The typical use would be to run the ec2-cost-calculate.rb script and then import into a spreadsheet application for further analysis. Another use would be to run the ec2-cost-calculate.rb script with cron, producing a weekly output file (an example of this: echo "0 0 * * 0 ec2-user /home/ec2-user/ec2-cost-calculate.rb --period day --region all --output file --file /home/ec2-user/ec2-cost-report`date +"%Y%m%d"`.txt" > /etc/cron.d/ec2-cost-calculate).
|
||||
# Directions For Use:
|
||||
#
|
||||
## Example of Use:
|
||||
#
|
||||
ec2-cost-calculate.rb --period day
|
||||
the above example would provide a list of all instances in all regions along with the daily cost of running each instance.
|
||||
## Required Parameters:
|
||||
#
|
||||
ec2-cost-calculate.rb has no parameter requirements. ec2-cost-calculate.rb defaults to all regions and hourly cost if no parameters are provided.
|
||||
#
|
||||
## Optional Parameters:
|
||||
#
|
||||
optional parameters are available by running ec2-cost-calculate.rb --help.
|
||||
# Additional Information:
|
||||
#
|
||||
Author: Colin Johnson / colin@cloudavail.com
|
||||
Date: 2012-06-17
|
||||
Version 0.1
|
||||
License Type: GNU GENERAL PUBLIC LICENSE, Version 3
|
245
ec2-cost-calculate-ruby/ec2-cost-calculate.rb
Executable file
245
ec2-cost-calculate-ruby/ec2-cost-calculate.rb
Executable file
|
@ -0,0 +1,245 @@
|
|||
#!/usr/bin/ruby
|
||||
access_key = ""
|
||||
secret_key = ""
|
||||
#default options are given below - user input can override any one of these
|
||||
options = {:fileoutputlocation => "~/ec-cost-calculate-result.txt", :output => "screen",:seperator => ",",:region => "all",:period => "hour",:multiplier => 1,:status => :running }
|
||||
#ec2cc_resources holds resources needed by ec2_cost_calculate, such as the output file handle
|
||||
ec2cc_resources = {}
|
||||
#list of valid statuses for an instance - will be used to validate user input
|
||||
instance_valid_statuses = [:pending, :running, :shutting_down, :terminated, :stopping, :stopped]
|
||||
|
||||
require 'optparse'
|
||||
require 'net/http'
|
||||
require 'rubygems'
|
||||
require 'aws-sdk'
|
||||
|
||||
class Instance
|
||||
#attr_accesors create variable setters and getters
|
||||
attr_accessor :id, :availability_zone, :region, :instance_type, :platform, :status
|
||||
attr_accessor :name
|
||||
attr_accessor :asg
|
||||
attr_accessor :price
|
||||
|
||||
#the variables set by "initialize" are those required for Instance instantiatiot
|
||||
def initialize(id,region,availability_zone,instance_type,platform,status)
|
||||
@id = id ; @region = region
|
||||
@availability_zone = availability_zone
|
||||
@instance_type = instance_type
|
||||
@platform = platform
|
||||
@status = status
|
||||
end
|
||||
|
||||
def get_price(instance_type,region,os,price_table,multiplier)
|
||||
price = price_table.match(/#{region},#{instance_type},#{os},.*/).to_s.split(",")
|
||||
@price = price[3].to_f * multiplier.to_f
|
||||
end
|
||||
|
||||
def output(options,ec2_object,ec2cc_resources)
|
||||
#outputstring below allows the initialization of how data should be outpout - it is used for both file and screen output. As for the use of a number of strings - I found the formatting easier to read but I'd be open to using one string if evidence supported that being a better way to do this
|
||||
outputstring = "#{ec2_object.id}","#{options[:seperator]}","#{ec2_object.region}","#{options[:seperator]}","#{ec2_object.platform}","#{options[:seperator]}","#{ec2_object.status}","#{options[:seperator]}","#{ec2_object.price}","#{options[:seperator]}","#{ec2_object.name}","#{options[:seperator]}","#{ec2_object.asg}","\n"
|
||||
case options[:output]
|
||||
when "file"
|
||||
ec2cc_resources[:ec2_output_file_handle].print outputstring
|
||||
when "screen"
|
||||
print outputstring
|
||||
else
|
||||
$stderr.print "error with output.\n"
|
||||
exit 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Region_Resource
|
||||
attr_accessor :region_name, :region_endpoint, :region_interface
|
||||
def initialize(region_name,region_endpoint,region_interface)
|
||||
@region_name = region_name
|
||||
@region_endpoint = region_endpoint
|
||||
@region_interface = region_interface
|
||||
end
|
||||
end
|
||||
|
||||
## ec2-cost-calculate ##
|
||||
## Initialization of ec2-cost-calculate
|
||||
#sets program name
|
||||
program_name = File.basename($PROGRAM_NAME)
|
||||
#gets and creates the credentials required for access
|
||||
credentialfile = ENV["AWS_CREDENTIAL_FILE"]
|
||||
if credentialfile.nil? || File.exists?(credentialfile) == false
|
||||
$stderr.print "The environment variable AWS_CREDENTIAL_FILE must exist and point to a valid credential file in order for ", program_name, " to run. The AWS_CREDENTIAL_FILE must contain also contain the two lines below:\n AWSAccessKeyId=<your access key>\n AWSSecretKey=<your secret key>\nPlease correct this error and run again.\n"
|
||||
exit 64
|
||||
end
|
||||
File.open(credentialfile,"r").each do |line|
|
||||
#below: sets access_key equal to line read in from "AWS_CREDENTIAL_FILE" that starts with "AWSAccessKeyId=" and removes trailing character
|
||||
if line.start_with?("AWSAccessKeyId=")
|
||||
access_key = line.split("=")[1].chomp!
|
||||
end
|
||||
#below: sets secret_key equal to line read in from "AWS_CREDENTIAL_FILE" that starts with "AWSSecretKeyId=" and removes trailing character
|
||||
if line.start_with?("AWSSecretKey=")
|
||||
secret_key = line.split("=")[1].chomp!
|
||||
end
|
||||
end
|
||||
|
||||
#gets and creates the price_table
|
||||
price_table = Net::HTTP.get('s3.amazonaws.com', '/colinjohnson-cloudavaildev/aws-ec2-cost-map.txt')
|
||||
#establishes an initial connection object to AWS
|
||||
ec2_interface = AWS::EC2.new( :access_key_id => access_key, :secret_access_key => secret_key)
|
||||
|
||||
#creates a container (currently, an array) for all ec2 objects
|
||||
ec2_container = {};
|
||||
#creates a container (currently, an array) for all regions resources
|
||||
region_container = {};
|
||||
#regions_aws is a list of all current Amazon regions
|
||||
regions_aws_all = ec2_interface.regions.map
|
||||
|
||||
#begin Options Parsing
|
||||
optparse = OptionParser.new do |opts|
|
||||
#sets options banner
|
||||
opts.banner = "Usage: #{program_name} [options]"
|
||||
#options processing: output
|
||||
opts.on("-o","--output OUTPUT","Output method. Accepts values \"screen\" or \"file.\" Default value is \"screen\".") do |output|
|
||||
#forces option to lowercase - easier to evaluate variables when always lowercase
|
||||
output.downcase!
|
||||
if (output == "screen" || output == "file")
|
||||
options[:output] = output
|
||||
else
|
||||
$stderr.print "You must specifiy an output method such as \"screen\" or \"file\". You specified \"", output, ".\"\n"
|
||||
exit 64
|
||||
end
|
||||
end
|
||||
#options process: filename is "file" is selected as output
|
||||
opts.on("-f","--file FILE","File output location. Only used when the output location \"File\" is selected.") do |file|
|
||||
#forces option to lowercase - easier to evaluate variables when always lowercase
|
||||
file.downcase!
|
||||
#the "file" option is only useful if the output is to a file
|
||||
options[:fileoutputlocation] = file
|
||||
end
|
||||
#options processing: used to create seperator
|
||||
opts.on('-s','--seperator SEPERATOR',"Character to be used for seperating fields. Default value is a comma.") do |seperator|
|
||||
if options[:output] != "file" && options[:output] != "screen"
|
||||
$stderr.print "You specified a seperator with format that was not \"screen\" or \"file\". You do not need to specify a seperator for the given format.\n"
|
||||
exit 64
|
||||
end
|
||||
options[:seperator] = seperator
|
||||
end
|
||||
#options processing for region
|
||||
opts.on('-r','--region REGION',"Region for which Instance Costs Should be Provided. Accepts values such as \"us-east-1\" or \"us-west-1.\" Default value is \"all\".") do |region_selected|
|
||||
region_selected.downcase!
|
||||
if region_selected == "all"
|
||||
$stderr.print "Region \"all\" has been selected.\n"
|
||||
else
|
||||
if regions_aws_all.detect {|region_evaluated| region_evaluated.name == region_selected }
|
||||
print "The region \"", region_selected, "\" has been selected.\n"
|
||||
options[:region] = region_selected
|
||||
else
|
||||
$stderr.print "You specified the region \"",region_selected,".\" You need to specify a valid region (example: \"us-east-1\") or region \"all\" for all regions.\n"
|
||||
exit 64
|
||||
end
|
||||
end
|
||||
end
|
||||
#options processing for period
|
||||
opts.on('-p','--period PERIOD',"Period for Which Costs Should Be Calculated. Accepts values \"hour\", \"day\", \"week\", \"month\" or \"year\". Default value is \"hour\".") do |period|
|
||||
period.downcase!
|
||||
case period
|
||||
when "hour"
|
||||
options[:multiplier] = 1
|
||||
when "day"
|
||||
options[:multiplier] = 24
|
||||
when "week"
|
||||
options[:multiplier] = 168
|
||||
when "month"
|
||||
options[:multiplier] = 720
|
||||
when "year"
|
||||
options[:multiplier] = 8760
|
||||
else
|
||||
$stderr.print "You specified the period \"",period,".\" Valid inputs are \"hour\", \"day\", \"week\", \"month\" or \"year.\"\n"
|
||||
exit 64
|
||||
end
|
||||
end
|
||||
#options processing for status
|
||||
opts.on('-s','--status STATUS',"Status for which instance cost should be gotten. Default is \"running\" status. Acceptable inputs are \"pending\" \"running\" \"shutting_down\", \"terminated\", \"stopping\", \"stopped.\"") do |status_selected|
|
||||
status_selected.downcase!
|
||||
#if instance_valid_statuses includes the user provided status, place in the options hash
|
||||
if instance_valid_statuses.include?(status_selected.to_sym)
|
||||
options[:status] = status_selected.to_sym
|
||||
#else - the status requested didn't exist in the hash, so exit and return error code.
|
||||
else
|
||||
$stderr.print "You specified the status \"",status_selected,".\" You need to specify a valid status such as \"running\" or \"pending.\"\n"
|
||||
exit 64
|
||||
end
|
||||
end
|
||||
end
|
||||
optparse.parse!
|
||||
|
||||
#file expansion and validation done outside of optparse
|
||||
#below performs expansion - ruby's File class does not support file expansion (for instance, ~/ec-cost-calculate-result.txt)
|
||||
if options[:output] == "file"
|
||||
ec2cc_output_file_location = File.expand_path(options[:fileoutputlocation])
|
||||
#if File exists, exit
|
||||
if File.exists?(ec2cc_output_file_location)
|
||||
$stderr.print "The file \"", ec2cc_output_file_location, "\" already exists. Rather than overwrite this file ", program_name, " will now exit.\n"
|
||||
exit 64
|
||||
else
|
||||
options[:fileoutputlocation] = ec2cc_output_file_location
|
||||
end
|
||||
ec2cc_resources[:ec2_output_file_handle] = File.open(ec2cc_output_file_location,'a')
|
||||
end
|
||||
|
||||
##handle region selection - this should be improved to iterate through a list of regions
|
||||
if options[:region] == "all"
|
||||
#set regions_aws_select to all
|
||||
regions_aws_all.each do |region|
|
||||
region_interface = AWS::EC2.new( :access_key_id => access_key, :secret_access_key => secret_key, :ec2_endpoint => region.endpoint)
|
||||
region_object = Region_Resource.new(region.name,region.endpoint,region_interface)
|
||||
region_container[region.to_s] = region_object
|
||||
end
|
||||
else
|
||||
regions_aws_all.each do |region|
|
||||
if options[:region] == region.name
|
||||
region_interface = AWS::EC2.new( :access_key_id => access_key, :secret_access_key => secret_key, :ec2_endpoint => region.endpoint)
|
||||
region_object = Region_Resource.new(region.name,region.endpoint,region_interface)
|
||||
region_container[region.to_s] = region_object
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#AWS.memoize "causes the sdk to hold onto information until the end of the memoization block" - rather than return information for each function. Performance improvement went from slow (~1 second per instance to 5 seconds for 200 instances)
|
||||
AWS.memoize do
|
||||
#First Code Block: passes in regional_resource (endpoint) - 1 call for each AWS region
|
||||
#Second Code Block: for each region, list all EC2 instances
|
||||
region_container.each do |region_name, region_object|
|
||||
#print "Getting Information from: ",region_object.region_name," using endpoint: ",region_object.region_interface.to_s,"\n"
|
||||
#for each region_interface, get all instances and perform actions below:
|
||||
region_object.region_interface.instances.each do |instance|
|
||||
#corrects an issue where instance.platform returns nil if a "linux" based instance - see https://forums.aws.amazon.com/thread.jspa?threadID=94567&tstart=0
|
||||
if instance.platform == nil
|
||||
platform = "linux"
|
||||
else
|
||||
platform = instance.platform
|
||||
end
|
||||
#creates an "Instance" object with a number of attributes
|
||||
ec2_object = Instance.new(instance.id,region_object.region_name,instance.availability_zone,instance.instance_type,platform,instance.status)
|
||||
ec2_object.name = instance.tags["Name"]
|
||||
ec2_object.asg = instance.tags["aws:autoscaling:groupName"]
|
||||
#gets price using Instance.price method
|
||||
ec2_object.price = ec2_object.get_price(ec2_object.instance_type,ec2_object.region,ec2_object.platform,price_table,options[:multiplier])
|
||||
#places each ec2_object into the ec2_container if the status of instance matches user requested status
|
||||
if options[:status] == instance.status
|
||||
ec2_container[instance.id] = ec2_object
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
#Prints Header
|
||||
headerstring = "instanceid","#{options[:seperator]}","region","#{options[:seperator]}","platform","#{options[:seperator]}","status","#{options[:seperator]}","cost","#{options[:seperator]}","name","#{options[:seperator]}","autoscalinggroup","\n"
|
||||
|
||||
case options[:output]
|
||||
when "screen"
|
||||
print headerstring
|
||||
when "file"
|
||||
ec2cc_resources[:ec2_output_file_handle].print headerstring
|
||||
end
|
||||
|
||||
#Prints Output for each EC2 object
|
||||
ec2_container.each do |ec2_instance_id,ec2_instance_object|
|
||||
ec2_instance_object.output(options,ec2_instance_object,ec2cc_resources)
|
||||
end
|
24
ec2-cost-calculate/README.txt
Normal file
24
ec2-cost-calculate/README.txt
Normal file
|
@ -0,0 +1,24 @@
|
|||
# Introduction:
|
||||
ec2-cost-calculate was created to easily sum the total of instances running in one or all regions. The typical use would be to run the ec2-cost-calculate script and then import into a spreadsheet application for further analysis. Another use would be to run the ec2-cost-calculate script with cron, producing a weekly output file (an example of this: echo "0 0 * * 0 ec2-user /home/ec2-user/ec2-cost-calculate.sh -p day -r all > /home/ec2-user/ec2-cost-report`date +"%Y%m%d"`.txt" > /etc/cron.d/ec2-cost-calculate.sh).
|
||||
# Directions For Use:
|
||||
#
|
||||
## Example of Use:
|
||||
#
|
||||
ec2-cost-calculate.sh -r us-east-1 -p day
|
||||
-
|
||||
the above example would provide a list of all instances in the region "us-east-1" along with the daily cost of running each instance.
|
||||
## Required Parameters:
|
||||
#
|
||||
ec2-cost-calculate has no parameter requirements. ec2-cost-calculate does, however, default to the region "us-east-1" and hourly cost if no parameters are provided.
|
||||
#
|
||||
## Optional Parameters:
|
||||
#
|
||||
-r <region> - the region you wish to calculate cost for: these arguments include "all" for all regions or us-east-1, us-west-1, us-west-2, eu-west-1, ap-southeast-1, ap-northeast-1 or sa-east-1
|
||||
-p <period> - the period for which you wish to calculate instance cost. Allowable arguments are hour, day, week, month or year.
|
||||
#
|
||||
# Additional Information:
|
||||
#
|
||||
Author: Colin Johnson / colin@cloudavail.com
|
||||
Date: 2012-03-07
|
||||
Version 0.5
|
||||
License Type: GNU GENERAL PUBLIC LICENSE, Version 3
|
109
ec2-cost-calculate/ec2-cost-calculate.sh
Executable file
109
ec2-cost-calculate/ec2-cost-calculate.sh
Executable file
|
@ -0,0 +1,109 @@
|
|||
#!/bin/bash -
|
||||
# Author: Colin Johnson / colin@cloudavail.com
|
||||
# Date: 2011-03-07
|
||||
# Version 0.5
|
||||
# License Type: GNU GENERAL PUBLIC LICENSE, Version 3
|
||||
#
|
||||
# Add Features:
|
||||
#multi-region, all-region
|
||||
#handle as-ag with min, mix and "desired cost"
|
||||
#randomize ec2-list temp file, keep from clobbering
|
||||
#####
|
||||
#ec2-cost-calculate start
|
||||
#confirms that executables required for succesful script execution are available
|
||||
prerequisitecheck()
|
||||
{
|
||||
for prerequisite in basename awk ec2-describe-instances
|
||||
do
|
||||
#use of "hash" chosen as it is a shell builtin and will add programs to hash table, possibly speeding execution. Use of type also considered - open to suggestions.
|
||||
hash $prerequisite &> /dev/null
|
||||
if [[ $? == 1 ]] #has exits with exit status of 70, executable was not found
|
||||
then echo "In order to use `basename $0`, the executable \"$prerequisite\" must be installed." 1>&2 ; exit 70
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
#calls prerequisitecheck function to ensure that all executables required for script execution are available
|
||||
prerequisitecheck
|
||||
|
||||
#handles options processing
|
||||
while getopts :r:p:o: opt
|
||||
do
|
||||
case $opt in
|
||||
p) period="$OPTARG";;
|
||||
r) region="$OPTARG";;
|
||||
o) output="$OPTARG";; #as of 2011-11-27 not implemented
|
||||
*) echo "Error with Options Input. Cause of failure is most likely that an unsupported parameter was passed or a parameter was passed without a corresponding option." 1>&2 ; exit 64;;
|
||||
esac
|
||||
done
|
||||
|
||||
# period validator and cost multiplier
|
||||
case $period in
|
||||
"") multiple=1; period=hour ;;
|
||||
hour|Hour) multiple=1; ;;
|
||||
day|Day) multiple=24;;
|
||||
week|Week) multiple=168;;
|
||||
month|Month) multiple=720;;
|
||||
year|Year) multiple=8760;;
|
||||
*) echo "The \"$period\" period does not exist. You must specify a valid period for which to calculate AWS cost (example: -p hour or -p day)." 1>&2 ; exit 64;;
|
||||
esac
|
||||
|
||||
# cost matrix
|
||||
|
||||
# region validator
|
||||
case $region in
|
||||
us-east-1|"") regionselected=(us-east-1);;
|
||||
us-west-1) regionselected=(us-west-1);;
|
||||
us-west-2) regionselected=(us-west-2);;
|
||||
eu-west-1) regionselected=(eu-west-1);;
|
||||
ap-southeast-1) regionselected=(ap-southeast-1);;
|
||||
ap-northeast-1) regionselected=(ap-northeast-1);;
|
||||
sa-east-1) regionselected=(sa-east-1);;
|
||||
all) regionselected=(us-east-1 us-west-1 us-west-2 eu-west-1 ap-southeast-1 ap-northeast-1 sa-east-1);;
|
||||
*) echo "The \"$region\" region does not exist. You must specify a valid region for which to calculate AWS cost (example: -r us-east-1 or -r us-west-1)." 1>&2 ; exit 64;;
|
||||
esac
|
||||
#ensures that headers are only printed on the first run
|
||||
runnumber=0
|
||||
# loops through a single region or all regions
|
||||
for currentregion in ${regionselected[@]}
|
||||
do
|
||||
ec2-describe-instances --region $currentregion --show-empty-fields --filter instance-state-name=running | awk -v currentregion=$currentregion -v period=$period -v multiple=$multiple -v runnumber=$runnumber '
|
||||
BEGIN {
|
||||
instancecount=0
|
||||
#sets cost for regions us-east-1 and us-west-2
|
||||
if ( currentregion == "us-east-1" || currentregion == "us-west-2" ) {
|
||||
cost["m1.small"]="0.08" ; cost["m1.medium"]="0.16" ; cost["m1.large"]="0.32" ; cost["m1.xlarge"]="0.64" ; cost["t1.micro"]="0.02" ; cost["m2.xlarge"]="0.45" ; cost["m2.2xlarge"]="0.9" ; cost["m2.4xlarge"]="1.8" ; cost["c1.medium"]="0.165" ; cost["c1.xlarge"]="0.66" ; cost["cc1.4xlarge"]="1.3" ; cost["cc2.8xlarge"]="2.4" ; cost["cg1.4xlarge"]="2.1" }
|
||||
#sets cost for regions us-west-1
|
||||
if ( currentregion == "us-west-1" ) {
|
||||
cost["m1.small"]="0.09" ; cost["m1.medium"]="0.18" ; cost["m1.large"]="0.36" ; cost["m1.xlarge"]="0.72" ; cost["t1.micro"]="0.025" ; cost["m2.xlarge"]="0.506" ; cost["m2.2xlarge"]="1.012" ; cost["m2.4xlarge"]="2.024" ; cost["c1.medium"]="0.186" ; cost["c1.xlarge"]="0.744" ; cost["cc1.4xlarge"]="" ; cost["cc2.8xlarge"]="" ; cost["cg1.4xlarge"]="" }
|
||||
#sets cost for regions eu-east-1a and ap-southeast-1
|
||||
if ( currentregion == "eu-west-1" || currentregion == "ap-southeast-1" ) {
|
||||
cost["m1.small"]="0.85" ; cost["m1.medium"]="0.17" ; cost["m1.large"]="0.34" ; cost["m1.xlarge"]="0.68" ; cost["t1.micro"]="0.02" ; cost["m2.xlarge"]="0.506" ; cost["m2.2xlarge"]="1.012" ; cost["m2.4xlarge"]="2.024" ; cost["c1.medium"]="0.186" ; cost["c1.xlarge"]="0.744" ; cost["cc1.4xlarge"]="" ; cost["cc2.8xlarge"]="" ; cost["cg1.4xlarge"]="" }
|
||||
#sets cost for region ap-northeast-1
|
||||
if ( currentregion == "ap-northeast-1" ) {
|
||||
cost["m1.small"]="0.092" ; cost["m1.medium"]="0.184" ; cost["m1.large"]="0.368" ; cost["m1.xlarge"]="0.736" ; cost["t1.micro"]="0.027" ; cost["m2.xlarge"]="0.518" ; cost["m2.2xlarge"]="1.036" ; cost["m2.4xlarge"]="2.072" ; cost["c1.medium"]="0.19" ; cost["c1.xlarge"]="0.76" ; cost["cc1.4xlarge"]="" ; cost["cc2.8xlarge"]="" ; cost["cg1.4xlarge"]="" }
|
||||
#sets cost for region sa-east-1
|
||||
if ( currentregion == "sa-east-1" ) {
|
||||
cost["m1.small"]="0.115" ; cost["m1.large"]="0.23" ; cost["m1.large"]="0.46" ; cost["m1.xlarge"]="0.92" ; cost["t1.micro"]="0.027" ; cost["m2.xlarge"]="0.68" ; cost["m2.2xlarge"]="1.36" ; cost["m2.4xlarge"]="2.72" ; cost["c1.medium"]="0.23" ; cost["c1.xlarge"]="0.92" ; cost["cc1.4xlarge"]="" ; cost["cc2.8xlarge"]="" ; cost["cg1.4xlarge"]="" }
|
||||
|
||||
if ( runnumber == 0 ) {
|
||||
printf ("%s %s %s %s %s %s %s %s\n", "InstanceID", "InstanceSize", "InstanceIP", "InstanceStatus", "InstanceName", "AutoScalingGroup", "Region", "InstanceCost" )
|
||||
}
|
||||
}
|
||||
|
||||
/^INSTANCE/ {
|
||||
if ( instancecount >= 1 ) {
|
||||
printf ("%s %s %s %s %s %s %s %s\n", instanceid, instancesize, instanceip, instancestatus, tag[0], tag[1], currentregion, cost[instancesize]*multiple )
|
||||
}
|
||||
instancecount++
|
||||
instanceid=$2 ; instancesize=$10 ; instanceip=$4 ; instancestatus=$6; tag[0]="Null" ; tag[1]="Null"
|
||||
}
|
||||
/^TAG/ {
|
||||
if ( $4 == "Name" ) tag[0]=$5
|
||||
if ( $4 == "aws:autoscaling:groupName" ) tag[1]=$5
|
||||
}
|
||||
#prints out last instance
|
||||
END { if ( instanceid != "" ) printf ("%s %s %s %s %s %s %s %s\n" , instanceid, instancesize, instanceip, instancestatus, tag[0] , tag[1], currentregion, cost[instancesize]*multiple ) }
|
||||
'
|
||||
runnumber=$((runnumber+1))
|
||||
done
|
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
|
15
ec2-write-storage-used/README.txt
Normal file
15
ec2-write-storage-used/README.txt
Normal file
|
@ -0,0 +1,15 @@
|
|||
# Introduction:
|
||||
ec2-write-storage-used was created to extend Amazon's default metrics for EC2 instances to include a metric for the amount of storage space used on an individual EC2 instance.
|
||||
# Directions For Use:
|
||||
#
|
||||
ec2-write-storage-used.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-14
|
||||
Version 0.1
|
||||
License Type: GNU GENERAL PUBLIC LICENSE, Version 3
|
17
ec2-write-storage-used/ec2-write-storage-used.sh
Normal file
17
ec2-write-storage-used/ec2-write-storage-used.sh
Normal file
|
@ -0,0 +1,17 @@
|
|||
#!/bin/bash -
|
||||
#get instance id - used for putting metric
|
||||
INSTANCE_ID=`GET 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%?}
|
||||
|
||||
#belowshould be changed to grep - get only everything after % space slash
|
||||
filesystemlist=`df -l | grep -i \/ | cut -c57-100` #add -l to restrict to local file systems
|
||||
|
||||
for filesystemmountpoint in $filesystemlist
|
||||
do
|
||||
storageused=`df | grep %\ *$filesystemmountpoint$ | grep -o [0-9]*% | tr -d %` #need to error check and possibly remove leading white space
|
||||
mon-put-data --region $INSTANCE_REGION --metric-name StorageUsed --namespace EC2/Storage --value $storageused --unit Percent --dimensions FileSystem=$filesystemmountpoint,InstanceId=$INSTANCE_ID
|
||||
done
|
||||
|
||||
#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-storage-used.sh" > /etc/cron.d/ec2-write-storage-used
|
29
rds-apply-alarms/README.txt
Normal file
29
rds-apply-alarms/README.txt
Normal file
|
@ -0,0 +1,29 @@
|
|||
# Introduction:
|
||||
rds-apply-alarms was created to easily apply alarms to anywhere from one to a number of Amazon RDS instances. The tool applies alarms for CPU Utilization, Feeable Memory, Swap Usage and Free Storage Space. rds-apply-alarms will run "out of the box", however the intent is rather to provide a template (and the logic) for managing multiple RDS instance's alarms.
|
||||
# Directions For Use:
|
||||
#
|
||||
## Example of Use:
|
||||
#
|
||||
rds-apply-alarms -d rds-instance-name -t name-of-sns-topic
|
||||
-
|
||||
the above example would apply alarms to "rds-instance-name" and, if any of these Alarms enter state "Alarm" would send a message to "name-of-topic."
|
||||
#
|
||||
## Required Parameters:
|
||||
#
|
||||
rds-apply-alarms requires the following two arguments:
|
||||
-d <rds-instance-name> - the name of the Database Instance for which you wish to apply alarms.
|
||||
-t <name-of-topic> - the name of the sns-topic where Alarms should be sent.
|
||||
#
|
||||
## Optional Parameters:
|
||||
#
|
||||
-a - pass the -a parameter to apply alarms to ALL RDS instances in a given region.
|
||||
-r <region> - region that contains the RDS instances(s) where alarms should be applied
|
||||
-e <evaluation period> - set to the number of evaluation periods before an SNS topic is notified.
|
||||
-p <previewmode> - set to "true" to preview what alarms would be applied.
|
||||
#
|
||||
# Additional Information:
|
||||
#
|
||||
Author: Colin Johnson / colin@cloudavail.com
|
||||
Date: 2012-03-07
|
||||
Version 0.5
|
||||
License Type: GNU GENERAL PUBLIC LICENSE, Version 3
|
115
rds-apply-alarms/rds-apply-alarms.sh
Executable file
115
rds-apply-alarms/rds-apply-alarms.sh
Executable file
|
@ -0,0 +1,115 @@
|
|||
#!/bin/bash -
|
||||
# Author: Colin Johnson / colin@cloudavail.com
|
||||
# Date: 2011-10-30
|
||||
# Version 0.1
|
||||
# License Type: GNU GENERAL PUBLIC LICENSE, Version 3
|
||||
#
|
||||
#rds-alarm-apply start
|
||||
|
||||
#confirms that executables required for succesful script execution are available
|
||||
prerequisitecheck()
|
||||
{
|
||||
for prerequisite in basename cut grep mon-put-metric-alarm rds-describe-db-instances
|
||||
do
|
||||
#use of "hash" chosen as it is a shell builtin and will add programs to hash table, possibly speeding execution. Use of type also considered - open to suggestions.
|
||||
hash $prerequisite &> /dev/null
|
||||
if [[ $? == 1 ]] #has exits with exit status of 70, executable was not found
|
||||
then echo "In order to use `basename $0`, the executable \"$prerequisite\" must be installed." 1>&2 ; exit 70
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
#calls prerequisitecheck function to ensure that all executables required for script execution are available
|
||||
prerequisitecheck
|
||||
|
||||
region="us-east-1"
|
||||
|
||||
#handles options processing
|
||||
while getopts :d:r:t:p:e:a opt
|
||||
do
|
||||
case $opt in
|
||||
d) dbname="$OPTARG";;
|
||||
r) region="$OPTARG";;
|
||||
t) topicname="$OPTARG";;
|
||||
e) evaluationperiod="$OPTARG";;
|
||||
p) previewmode="$OPTARG";;
|
||||
a) allrds="true";;
|
||||
*) echo "Error with Options Input. Cause of failure is most likely that an unsupported parameter was passed or a parameter was passed without a corresponding option." 1>&2 ; exit 64;;
|
||||
esac
|
||||
done
|
||||
|
||||
#sets previewmode - will echo commands rather than performing work
|
||||
case $previewmode in
|
||||
true|True) previewmode="echo"; echo "Preview Mode is set to \"True.\"" 1>&2 ;;
|
||||
""|false|False) previewmode="";;
|
||||
*) echo "You specified \"$previewmode\" for Preview Mode. If specifying a Preview Mode you must specificy either \"true\" or \"false.\"" 1>&2 ; exit 64;;
|
||||
esac
|
||||
|
||||
# evaluationperiod validator - must be a number between 1 and 99
|
||||
case $evaluationperiod in
|
||||
"") evaluationperiod=1;;
|
||||
[1-99]) ;;
|
||||
*) echo "You specified \"$evaluationperiod\" for your evaluation period. If specifying an evalaution period you must specify a period between 1 and 99." 1>&2 ; exit 64;;
|
||||
esac
|
||||
|
||||
# region validator
|
||||
case $region in
|
||||
us-east-1|us-west-2|us-west-1|eu-west-1|ap-southeast-1|ap-northeast-1|sa-east-1) ;;
|
||||
*) echo "The \"$region\" region does not exist. You must specify a valid region (example: -r us-east-1 or -r us-west-2)." 1>&2 ; exit 64;;
|
||||
esac
|
||||
|
||||
# single RDS instance validator - runs if applying to only one instance
|
||||
if [[ $allrds != "true" ]]
|
||||
then
|
||||
if [[ $dbname == "" ]]
|
||||
then echo "You did not specify an RDS instance. You must select an RDS instance to apply alarms to." 1>&2 ; exit 64
|
||||
fi
|
||||
if [[ `rds-describe-db-instances $dbname --region $region 2> /dev/null` =~ .*DBINSTANCE.*$dbame ]]
|
||||
then echo "RDS instance $dbname has been found."
|
||||
else echo "The RDS instance \"$dbname\" does not exist. You must specify a valid RDS instance." 1>&2 ; exit 64
|
||||
fi
|
||||
fi
|
||||
|
||||
# multiple RDS instance validator - runs if applying to all instances
|
||||
if [[ $allrds == "true" ]]
|
||||
then
|
||||
if [[ $dbname != "" ]]
|
||||
then
|
||||
echo "You specified both \"All\" RDS instances and \"$dbname\" to apply alarms to. You must specify either one particular RDS instance (-d <dbname>) or all RDS instances (-a)." 1>&2 ; exit 64
|
||||
else
|
||||
echo "Alarms will be applied to all RDS instances."
|
||||
fi
|
||||
fi
|
||||
|
||||
rdsinstancelist=`rds-describe-db-instances $dbname --region $region --show-long | grep -i DBINSTANCE | cut -d ',' -f2`
|
||||
|
||||
for rdsinstancename in $rdsinstancelist
|
||||
do
|
||||
echo "Applying Alarms to RDS instance $rdsinstancename."
|
||||
|
||||
#start of apply-alarms
|
||||
rdsinstancetype=`rds-describe-db-instances $rdsinstancename --region $region --show-long | cut -d ',' -f4`
|
||||
rdstorage=`rds-describe-db-instances $rdsinstancename --region $region --show-long | cut -d ',' -f6`
|
||||
|
||||
#given rds instance type, determines what 5% of freeable memory is
|
||||
case $rdsinstancetype in
|
||||
db.m1.small) lowfreeablememory=0.85E8;; #1.7 GB memory
|
||||
db.m1.large) lowfreeablememory=3.75E8;; #7.5 GB memory
|
||||
db.m1.xlarge) lowfreeablememory=7.5E8;; #15 GB memory
|
||||
db.m2.xlarge) lowfreeablememory=8.55E8;; #17.1 GB memory
|
||||
db.m2.2xlarge) lowfreeablememory=17.0E8;; #34 GB memory
|
||||
db.m2.4xlarge) lowfreeablememory=34.0E8;; #68 GB memory
|
||||
*) echo "An error has occured when attempting to set low memory threshold. Please contact the author of rds-apply-alarms." 1>&2 ; exit 64;;
|
||||
esac
|
||||
#determines the low storage alert - at less than 10% of rdsstorage
|
||||
lowstorage="${rdstorage}.0E8"
|
||||
|
||||
$previewmode mon-put-metric-alarm --alarm-name $rdsinstancename-RDS-CPUUtilization-Critical --metric-name CPUUtilization --namespace AWS/RDS --statistic Average --period 300 --threshold 90 --comparison-operator GreaterThanThreshold --dimensions DBInstanceIdentifier=$rdsinstancename --evaluation-periods $evaluationperiod --unit Percent --alarm-actions $topicname --region $region
|
||||
|
||||
$previewmode mon-put-metric-alarm --alarm-name $rdsinstancename-RDS-FreeableMemory-Critical --metric-name FreeableMemory --namespace AWS/RDS --statistic Average --period 300 --threshold $lowfreeablememory --comparison-operator LessThanThreshold --dimensions DBInstanceIdentifier=$rdsinstancename --evaluation-periods $evaluationperiod --unit Bytes --alarm-actions $topicname --region $region
|
||||
|
||||
$previewmode mon-put-metric-alarm --alarm-name $rdsinstancename-RDS-SwapUsage-Critical --metric-name SwapUsage --namespace AWS/RDS --statistic Maximum --period 300 --threshold 1048576 --comparison-operator GreaterThanThreshold --dimensions DBInstanceIdentifier=$rdsinstancename --evaluation-periods $evaluationperiod --unit Bytes --alarm-actions $topicname --region $region
|
||||
|
||||
$previewmode mon-put-metric-alarm --alarm-name $rdsinstancename-RDS-FreeStorageSpace-Critical --metric-name FreeStorageSpace --namespace AWS/RDS --statistic Minimum --period 300 --threshold $lowstorage --comparison-operator LessThanThreshold --dimensions DBInstanceIdentifier=$rdsinstancename --evaluation-periods $evaluationperiod --unit Bytes --alarm-actions $topicname --region $region
|
||||
|
||||
done
|
24
rds-cost-calculate/README.txt
Normal file
24
rds-cost-calculate/README.txt
Normal file
|
@ -0,0 +1,24 @@
|
|||
# Introduction:
|
||||
rds-cost-calculate was created to easily sum the total of RDS instances running in one or all regions. The typical use would be to run the rds-cost-calculate script and then import into a spreadsheet application for further analysis. Another use would be to run the rds-cost-calculate script with cron, producing a weekly output file (an example of this: echo "0 0 * * 0 ec2-user /home/ec2-user/rds-cost-calculate.sh -p day -r all > /home/ec2-user/rds-cost-report`date +"%Y%m%d"`.txt" > /etc/cron.d/rds-cost-calculate.sh).
|
||||
# Directions For Use:
|
||||
#
|
||||
## Example of Use:
|
||||
#
|
||||
rds-cost-calculate.sh -r us-east-1 -p day
|
||||
-
|
||||
the above example would provide a list of all RDS instances in the region "us-east-1" along with the daily cost of running each RDS instance.
|
||||
## Required Parameters:
|
||||
#
|
||||
rds-cost-calculate has no parameter requirements. rds-cost-calculate does, however, default to the region "us-east-1" and hourly cost if no parameters are provided.
|
||||
#
|
||||
## Optional Parameters:
|
||||
#
|
||||
-r <region> - the region you wish to calculate cost for: these arguments include "all" for all regions or us-east-1, us-west-1, us-west-2, eu-west-1, ap-southeast-1, ap-northeast-1 or sa-east-1
|
||||
-p <period> - the period for which you wish to calculate instance cost. Allowable arguments are hour, day, week, month or year.
|
||||
#
|
||||
# Additional Information:
|
||||
#
|
||||
Author: Colin Johnson / colin@cloudavail.com
|
||||
Date: 2012-03-07
|
||||
Version 0.5
|
||||
License Type: GNU GENERAL PUBLIC LICENSE, Version 3
|
118
rds-cost-calculate/rds-cost-calculate.sh
Executable file
118
rds-cost-calculate/rds-cost-calculate.sh
Executable file
|
@ -0,0 +1,118 @@
|
|||
#!/bin/bash -
|
||||
# Author: Colin Johnson / colin@cloudavail.com
|
||||
# Date: 2011-03-07
|
||||
# Version 0.5
|
||||
# License Type: GNU GENERAL PUBLIC LICENSE, Version 3
|
||||
#
|
||||
# Add Features:
|
||||
#####
|
||||
#rds-cost-calculate start
|
||||
#confirms that executables required for succesful script execution are available
|
||||
prerequisitecheck()
|
||||
{
|
||||
for prerequisite in basename awk rds-describe-db-instances
|
||||
do
|
||||
#use of "hash" chosen as it is a shell builtin and will add programs to hash table, possibly speeding execution. Use of type also considered - open to suggestions.
|
||||
hash $prerequisite &> /dev/null
|
||||
if [[ $? == 1 ]] #has exits with exit status of 70, executable was not found
|
||||
then echo "In order to use `basename $0`, the executable \"$prerequisite\" must be installed." 1>&2 ; exit 70
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
#calls prerequisitecheck function to ensure that all executables required for script execution are available
|
||||
prerequisitecheck
|
||||
|
||||
#handles options processing
|
||||
while getopts :r:p:o: opt
|
||||
do
|
||||
case $opt in
|
||||
p) period="$OPTARG";;
|
||||
r) region="$OPTARG";;
|
||||
o) output="$OPTARG";; #as of 2011-12-30 not implemented
|
||||
*) echo "Error with Options Input. Cause of failure is most likely that an unsupported parameter was passed or a parameter was passed without a corresponding option." 1>&2 ; exit 64;;
|
||||
esac
|
||||
done
|
||||
|
||||
# period validator and cost multiplier
|
||||
case $period in
|
||||
"") multiple=1; period=hour ;;
|
||||
hour|Hour) multiple=1; ;;
|
||||
day|Day) multiple=24;;
|
||||
week|Week) multiple=168;;
|
||||
month|Month) multiple=720;;
|
||||
year|Year) multiple=8760;;
|
||||
*) echo "The \"$period\" period does not exist. You must specify a valid period for which to calculate AWS cost (example: -p hour or -p day)." 1>&2 ; exit 64;;
|
||||
esac
|
||||
|
||||
# cost matrix
|
||||
|
||||
# region validator
|
||||
case $region in
|
||||
us-east-1|"") regionselected=(us-east-1);;
|
||||
us-west-1) regionselected=(us-west-1);;
|
||||
us-west-2) regionselected=(us-west-2);;
|
||||
eu-west-1) regionselected=(eu-west-1);;
|
||||
ap-southeast-1) regionselected=(ap-southeast-1);;
|
||||
ap-northeast-1) regionselected=(ap-northeast-1);;
|
||||
sa-east-1) regionselected=(sa-east-1);;
|
||||
all) regionselected=(us-east-1 us-west-1 us-west-2 eu-west-1 ap-southeast-1 ap-northeast-1 sa-east-1);;
|
||||
*) echo "The \"$region\" region does not exist. You must specify a valid region for which to calculate AWS cost (example: -r us-east-1 or -r us-west-1)." 1>&2 ; exit 64;;
|
||||
esac
|
||||
#ensures that headers are only printed on the first run
|
||||
runnumber=0
|
||||
# loops through a single region or all regions
|
||||
for currentregion in ${regionselected[@]}
|
||||
do
|
||||
rds-describe-db-instances --region $currentregion --show-long --max-records 100 | awk -v currentregion=$currentregion -v period=$period -v multiple=$multiple -v runnumber=$runnumber '
|
||||
BEGIN {
|
||||
FS = ","
|
||||
dbinstancecount=0
|
||||
#sets cost for regions us-east-1 and us-west-2
|
||||
if ( currentregion == "us-east-1" || currentregion == "us-west-2" ) {
|
||||
cost["db.t1.micro"]="0.025" ; cost["db.m1.small"]="0.105" ; cost["db.m1.large"]="0.415" ; cost["db.m1.xlarge"]="0.83" ; cost["db.m2.xlarge"]="0.585" ; cost["db.m2.2xlarge"]="1.17" ; cost["db.m2.4xlarge"]="2.34" }
|
||||
#sets cost for regions eu-east-1, ap-southeast-1 and us-west-1
|
||||
if ( currentregion == "eu-west-1" || currentregion == "ap-southeast-1" || currentregion == "us-west-1" ) {
|
||||
cost["db.t1.micro"]="0.035" ; cost["db.m1.small"]="0.115" ; cost["db.m1.large"]="0.455" ; cost["db.m1.xlarge"]="0.92" ; cost["db.m2.xlarge"]="0.655" ; cost["db.m2.2xlarge"]="1.315" ; cost["db.m2.4xlarge"]="2.63" }
|
||||
#sets cost for region ap-northeast-1
|
||||
if ( currentregion == "ap-northeast-1" ) {
|
||||
cost["db.t1.micro"]="0.035" ; cost["db.m1.small"]="0.12" ; cost["db.m1.large"]="0.48" ; cost["db.m1.xlarge"]="0.955" ; cost["db.m2.xlarge"]="0.675" ; cost["db.m2.2xlarge"]="1.35" ; cost["db.m2.4xlarge"]="2.695" }
|
||||
#sets cost for region sa-east-1
|
||||
if ( currentregion == "sa-east-1" ) {
|
||||
cost["db.t1.micro"]="0.035" ; cost["db.m1.small"]="0.15" ; cost["db.m1.large"]="0.6" ; cost["db.m1.xlarge"]="1.2" ; cost["db.m2.xlarge"]="0.88" ; cost["db.m2.2xlarge"]="1.76" ; cost["db.m2.4xlarge"]="3.52" }
|
||||
|
||||
if ( runnumber == 0 ) {
|
||||
printf ("%s %s %s %s %s %s %s %s %s\n", "DBInstanceId", "Class", "Storage", "Status", "SecurityGroup" , "EndpointAddress", "MultiAZ", "Region", "InstanceCost" )
|
||||
}
|
||||
}
|
||||
|
||||
/^DBINSTANCE/ {
|
||||
if ( dbinstancecount >= 1 ) {
|
||||
if ( multiaz == "y" ) {
|
||||
multiazmultiple=2
|
||||
} else {
|
||||
multiazmultiple=1 ;
|
||||
}
|
||||
#prints previous instance
|
||||
printf ("%s %s %s %s %s %s %s %s %s\n", dbinstanceid, class, storage, status, secgroup, endpointaddress, multiaz, currentregion, cost[class]*multiple*multiazmultiple )
|
||||
}
|
||||
dbinstancecount++
|
||||
#loads current instance
|
||||
dbinstanceid=$2 ; class=$4 ; storage=$6 ; status=$8 ; secgroup="Null" ; endpointaddress=$9 ; multiaz=$23
|
||||
}
|
||||
#gets security group of instance
|
||||
/^SECGROUP/ {
|
||||
if ( $1 == "SECGROUP" ) secgroup=$2
|
||||
}
|
||||
#prints out last instance
|
||||
END { if ( dbinstanceid != "" ) {
|
||||
if ( multiaz == "y" ) {
|
||||
multiazmultiple=2;
|
||||
} else {
|
||||
multiazmultiple=1;
|
||||
}
|
||||
printf ("%s %s %s %s %s %s %s %s %s\n", dbinstanceid, class, storage, status, secgroup, endpointaddress, multiaz, currentregion, cost[class]*multiple*multiazmultiple ) }
|
||||
}
|
||||
'
|
||||
runnumber=$((runnumber+1))
|
||||
done
|
Loading…
Reference in New Issue
Block a user