diff --git a/debian/changelog b/debian/changelog index 48191b11..a9abb8d2 100644 --- a/debian/changelog +++ b/debian/changelog @@ -32,6 +32,9 @@ byobu (4.3) unreleased; urgency=low west-1, usr/share/byobu/ec2/rates.us_va => usr/share/byobu/ec2/rates.us-east-1, usr/bin/byobu-janitor: - rework ec2_cost entirely, using metaservice; much more accurate + * usr/lib/byobu/ec2_cost, usr/share/byobu/ec2/Makefile.am, + usr/share/byobu/ec2/us-west-1 => usr/share/byobu/ec2/rates.us-west- + 1: fix a couple of bugs [ Scott Moser ] * usr/lib/byobu/.shutil: fix rounding across a decimal point in fpdiv() diff --git a/usr/lib/byobu/ec2_cost b/usr/lib/byobu/ec2_cost index b60c59b4..2aaf0ea9 100755 --- a/usr/lib/byobu/ec2_cost +++ b/usr/lib/byobu/ec2_cost @@ -32,32 +32,39 @@ for arg in $@; do done # Try to use metadata service -zone=$(wget -q -O - http://169.254.169.254/latest/meta-data/placement/availability-zone || echo "us-east-1") -. "$BYOBU_PREFIX/share/$PKG/ec2/rates.${zone%?}" -if type=$(wget -q -O - http://169.254.169.254/latest/meta-data/instance-type | sed -e "s/\./_/g"); then +if host 169.254.169.254 >/dev/null 2>&1; then + zone=$(wget -q -O - http://169.254.169.254/latest/meta-data/placement/availability-zone) + . "$BYOBU_PREFIX/share/$PKG/ec2/rates.${zone%?}" + type=$(wget -q -O - http://169.254.169.254/latest/meta-data/instance-type | sed -e "s/\./_/g") eval RATE="\$$type" + file_to_stat="$DATA/.ec2_instance_type" + [ -f "$file_to_stat" ] || wget -q -O "$file_to_stat" http://169.254.169.254/latest/meta-data/instance-type else - # Count CPUs, Memory, Architecture + . "$BYOBU_PREFIX/share/$PKG/ec2/rates."* + # Count CPUs, Memory, Architecture, hours cpu=$(grep -c "^processor.*:" /proc/cpuinfo) || cpu=1 mem=$(grep ^MemTotal /proc/meminfo | awk '{print $2}') + # /etc/hostname gets created at installation (but might get updated...other ideas?) + file_to_stat="/etc/hostname" # Guess this system's going rate, based on mem available (m* types) if [ $mem -lt 700000 ]; then - RATE=$T1_MICRO + RATE=$t1_micro elif [ $mem -gt 64000000 ]; then - RATE=$M2_4XLARGE + RATE=$m2_4xlarge elif [ $mem -gt 32000000 ]; then - RATE=$M2_2XLARGE + RATE=$m2_2xlarge elif [ $mem -gt 16000000 ]; then - RATE=$M2_XLARGE + RATE=$m2_xlarge elif [ $mem -gt 14000000 ]; then - RATE=$M1_XLARGE + RATE=$m1_xlarge elif [ $mem -gt 7000000 ]; then - RATE=$M1_LARGE + RATE=$m1_large else # Otherwise, scale based on number of cpu's (c* types) - RATE=$(echo "$cpu" "$M1_SMALL" | awk '{printf "%f", $1*$2}') + RATE=$(echo "$cpu" "$m1_small" | awk '{printf "%f", $1*$2}') fi fi +hours=$(((`date +%s` - `stat --printf %Y $file_to_stat`) / 60 / 60 + 1)) # Data Transfer Cost Basis # Incoming $0.10/GB @@ -79,7 +86,6 @@ rx_gb=$(echo ${rx_gb%% *} | awk '{ printf "%f", $1 / 1024 / 1024 / 1024 }') network_cost=`echo "$tx_gb" "$TX_RATE" "$rx_gb" "$RX_RATE" | awk '{printf "%f %f", $1*$2, $3*$4}' | awk '{printf "%f", $1 + $2}'` # Calculate uptime cost -hours=$(((`date +%s` - `stat --printf %Z /etc/hostname`) / 60 / 60 + 1)) uptime_cost=`echo "$hours" | awk "{printf \"%f\", "$RATE" * $hours}"` total_cost=`echo "$network_cost" "$uptime_cost" | awk '{printf "%.2f", $1 + $2}'` diff --git a/usr/share/byobu/ec2/Makefile.am b/usr/share/byobu/ec2/Makefile.am index 1037dab4..f35258f7 100644 --- a/usr/share/byobu/ec2/Makefile.am +++ b/usr/share/byobu/ec2/Makefile.am @@ -1,2 +1,2 @@ ec2dir = $(datadir)/@PACKAGE@/ec2 -ec2_DATA = rates.ap-northeast-1 rates.ap-southeast-1 rates.eu-west-1 rates.us-east-1 +ec2_DATA = rates.ap-northeast-1 rates.ap-southeast-1 rates.eu-west-1 rates.us-east-1 rates.us-west-1 diff --git a/usr/share/byobu/ec2/us-west-1 b/usr/share/byobu/ec2/rates.us-west-1 similarity index 100% rename from usr/share/byobu/ec2/us-west-1 rename to usr/share/byobu/ec2/rates.us-west-1