Wednesday, 19 August 2015

AWS Spot Pricing

This is done in 2 scripts :

./spothead.sh

#!/bin/bash

n=$(date "+%H:%M:%S")
while read server
do
#var=$(. ./spotprice.sh "${server}")
#echo "AFTER: $var"
./spotprice.sh "${server}"
done < types.txt
echo ""
printf "PN: -  TOP most value shows the SMOOTHEST graph  -\n    -   Rest of the values follows accordingly   -\n    -        LAST value represent WORST!         -"
echo ""
echo ""
echo "-------------------------------------------------------"
printf "|   Gausian Curve    |  Current Price  |    Server    | \n"
printf "| (top value = best) |  "%s\ at" "$n"   |    (Type)    | \n"
echo "-------------------------------------------------------"
cat merged.txt | sort -n
echo ""
rm -fr merged.txt

========================================================================


./spotprice.sh

#!/bin/bash

NOW=$(date "+%Y-%m-%dT%H:%M:%S")
REF=$(date -d "-1 days" +"%Y-%m-%dT%H:%M:%S")
aws ec2 describe-spot-price-history --instance-types $1 --availability-zone us-east-1e --product-description "Linux/UNIX (Amazon VPC)" --start-time $REF --end-time $NOW --query 'SpotPriceHistory[*].[SpotPrice]' --output text >> number.txt
SUM=$(awk '{delta = $1 - avg; avg += delta / NR; mean2 += delta * ($1 - avg); } END { printf "%0.7f \n" , sqrt(mean2 / NR); }' number.txt)
CP=$(tail -1 number.txt)
echo "      $SUM          $CP        $1" >> merged.txt
rm -fr number.txt


That will get the job done!!

No comments:

Post a Comment