From 8a555b2f91e7303e6adb2596dac65e8bf89b67c4 Mon Sep 17 00:00:00 2001 From: Dustin Kirkland Date: Wed, 3 Mar 2010 11:52:06 -0600 Subject: [PATCH] * usr/bin/byobu-export, usr/lib/byobu/ec2_cost, usr/share/byobu/ec2/rates.eu_ie, usr/share/byobu/ec2/rates.us_ca, usr/share/byobu/ec2/rates.us_va: - update ec2 pricing model, allow for local overrides of prices via a sourced symlink or bespoke file in $HOME/.byobu/ec2_rates --- debian/changelog | 6 ++++- usr/bin/byobu-export | 1 + usr/lib/byobu/ec2_cost | 40 ++++++++++++++++++++------------- usr/share/byobu/ec2/rates.eu_ie | 13 +++++++++++ usr/share/byobu/ec2/rates.us_ca | 13 +++++++++++ usr/share/byobu/ec2/rates.us_va | 13 +++++++++++ 6 files changed, 70 insertions(+), 16 deletions(-) create mode 100644 usr/share/byobu/ec2/rates.eu_ie create mode 100644 usr/share/byobu/ec2/rates.us_ca create mode 100644 usr/share/byobu/ec2/rates.us_va diff --git a/debian/changelog b/debian/changelog index 5375e088..3e11c97d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,10 @@ byobu (2.60) unreleased; urgency=low - * UNRELEASED + * usr/bin/byobu-export, usr/lib/byobu/ec2_cost, + usr/share/byobu/ec2/rates.eu_ie, usr/share/byobu/ec2/rates.us_ca, + usr/share/byobu/ec2/rates.us_va: + - update ec2 pricing model, allow for local overrides of prices + via a sourced symlink or bespoke file in $HOME/.byobu/ec2_rates -- Dustin Kirkland Fri, 26 Feb 2010 10:43:00 -0600 diff --git a/usr/bin/byobu-export b/usr/bin/byobu-export index 672ae5d0..8e86983e 100755 --- a/usr/bin/byobu-export +++ b/usr/bin/byobu-export @@ -91,6 +91,7 @@ cp /etc/$PKG/statusrc "$DIR/.$PKG/status" echo "source \$HOME/.$PKG/profile" > "$DIR/.screenrc" echo "source \$HOME/.$PKG/usr/share/$PKG/keybindings/common" > "$DIR/.$PKG/keybindings" ln -sf usr/share/$PKG/profiles/common "$DIR/.$PKG/profile" +ln -sf usr/share/$PKG/ec2/rates.us_ca "$DIR/.$PKG/ec2_rates" # Some gardening; update paths to be $HOME-based for i in $(ls /usr/bin/$PKG-* | grep -v "install"); do diff --git a/usr/lib/byobu/ec2_cost b/usr/lib/byobu/ec2_cost index d2cde3c4..3115b7bc 100755 --- a/usr/lib/byobu/ec2_cost +++ b/usr/lib/byobu/ec2_cost @@ -29,26 +29,36 @@ for arg in $@; do esac done -# Approximate Instance Cost Basis -# US Europe -# Small (1cpu, 32bit) $0.10/h $0.11/h -# Medium (2cpu, 32bit) $0.20/h $0.22/h -# Large (4cpu, 64bit) $0.40/h $0.44/h -# XLarge (8cpu, 64bit) $0.80/h $0.88/h +# Get the going rates +[ -r "$HOME/.$PKG/ec2_rates" ] || ln -s /usr/share/$PKG/ec2/rates.us_ca "$HOME/.$PKG/ec2_rates" +. "$HOME/.$PKG/ec2_rates" || exit 1 -# Count CPUs -cpu_count=`grep -c "^processor.*:" /proc/cpuinfo` -[ -z "$cpu_count" ] && cpu_count=1 -# Apply the going rate -CPU_RATE=`echo "$cpu_count" | awk '{printf "%f", 0.10*$1}'` -# BUG: Some logic needed here to add 10% cost for Europe instances? +# Count CPUs, Memory, Architecture +cpu=$(grep -c "^processor.*:" /proc/cpuinfo) || cpu=1 +mem=$(grep ^MemTotal /proc/meminfo | awk '{print $2}') + +# Guess this system's going rate, based on mem available (m* types) +if [ $mem -gt 64000000 ]; then + RATE=$M2_4XLARGE +elif [ $mem -gt 32000000 ]; then + RATE=$M2_2XLARGE +elif [ $mem -gt 16000000 ]; then + RATE=$M2_XLARGE +elif [ $mem -gt 14000000 ]; then + RATE=$M1_XLARGE +elif [ $mem -gt 7000000 ]; then + RATE=$M1_LARGE +else + # Otherwise, scale based on number of cpu's (c* types) + RATE=$(echo "$cpu" "$M1_SMALL" | awk '{printf "%f", $1*$2}') +fi # Data Transfer Cost Basis # Incoming $0.10/GB # Outgoing $0.17/GB # (This gets more complex if you use >1TB/mo) RX_RATE="0.10" -TX_RATE="0.17" +TX_RATE="0.15" # Auto detect network interface IF=`tail -n1 /proc/net/route | awk '{print $1}'` @@ -64,7 +74,7 @@ network_cost=`echo "$tx_gb" "$TX_RATE" "$rx_gb" "$RX_RATE" | awk '{printf "%f %f # BUG: This will only calculate uptime since boot! # Some additional input will be required to account for reboots!!! hours=`awk '{printf "%f", 1 + $1 / 60 / 60 }' /proc/uptime | sed 's/\..*$//' ` -uptime_cost=`echo "$hours" | awk "{printf \"%f\", "$CPU_RATE" * $hours}"` +uptime_cost=`echo "$hours" | awk "{printf \"%f\", "$RATE" * $hours}"` total_cost=`echo "$network_cost" "$uptime_cost" | awk '{printf "%.2f", $1 + $2}'` if [ "$DETAIL" = "1" ]; then @@ -75,7 +85,7 @@ if [ "$DETAIL" = "1" ]; then echo " Network recv: $rx_gb GB @ \$$TX_RATE/GB" echo " Network cost: \$$network_cost" echo "------------------------------------------------" - echo " Uptime: $hours hr @ \$$CPU_RATE/hr" + echo " Uptime: $hours hr @ \$$RATE/hr" echo " Uptime cost: \$$uptime_cost" echo "------------------------------------------------" echo "Total cost: ~\$$total_cost" diff --git a/usr/share/byobu/ec2/rates.eu_ie b/usr/share/byobu/ec2/rates.eu_ie new file mode 100644 index 00000000..e005d3da --- /dev/null +++ b/usr/share/byobu/ec2/rates.eu_ie @@ -0,0 +1,13 @@ +# 2010-03-03: Approximate Instance Cost Basis per hour from +# http://aws.amazon.com/ec2/instance-types/ +# http://aws.amazon.com/ec2/#pricing +# for EU - Ireland +M1_SMALL="0.095" +M1_LARGE="0.38" +M1_XLARGE="0.76" +M2_XLARGE="0.57" +M2_2XLARGE="1.34" +M2_4XLARGE="2.68" +C1_MEDIUM="0.19" +C1_XLARGE="0.76" + diff --git a/usr/share/byobu/ec2/rates.us_ca b/usr/share/byobu/ec2/rates.us_ca new file mode 100644 index 00000000..c7866fba --- /dev/null +++ b/usr/share/byobu/ec2/rates.us_ca @@ -0,0 +1,13 @@ +# 2010-03-03: Approximate Instance Cost Basis per hour from +# http://aws.amazon.com/ec2/instance-types/ +# http://aws.amazon.com/ec2/#pricing +# for US - N. California +M1_SMALL="0.095" +M1_LARGE="0.38" +M1_XLARGE="0.76" +M2_XLARGE="0.57" +M2_2XLARGE="1.34" +M2_4XLARGE="2.68" +C1_MEDIUM="0.19" +C1_XLARGE="0.76" + diff --git a/usr/share/byobu/ec2/rates.us_va b/usr/share/byobu/ec2/rates.us_va new file mode 100644 index 00000000..0c271536 --- /dev/null +++ b/usr/share/byobu/ec2/rates.us_va @@ -0,0 +1,13 @@ +# 2010-03-03: Approximate Instance Cost Basis per hour from +# http://aws.amazon.com/ec2/instance-types/ +# http://aws.amazon.com/ec2/#pricing +# for US - N. Virginia +M1_SMALL="0.085" +M1_LARGE="0.34" +M1_XLARGE="0.68" +M2_XLARGE="0.50" +M2_2XLARGE="1.20" +M2_4XLARGE="2.40" +C1_MEDIUM="0.17" +C1_XLARGE="0.68" +