mirror of
https://github.com/dustinkirkland/byobu
synced 2025-08-23 06:36:17 -07:00
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
This commit is contained in:
parent
198f9c5ee3
commit
527430da9e
4 changed files with 22 additions and 13 deletions
3
debian/changelog
vendored
3
debian/changelog
vendored
|
@ -32,6 +32,9 @@ byobu (4.3) unreleased; urgency=low
|
||||||
west-1, usr/share/byobu/ec2/rates.us_va =>
|
west-1, usr/share/byobu/ec2/rates.us_va =>
|
||||||
usr/share/byobu/ec2/rates.us-east-1, usr/bin/byobu-janitor:
|
usr/share/byobu/ec2/rates.us-east-1, usr/bin/byobu-janitor:
|
||||||
- rework ec2_cost entirely, using metaservice; much more accurate
|
- 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 ]
|
[ Scott Moser ]
|
||||||
* usr/lib/byobu/.shutil: fix rounding across a decimal point in fpdiv()
|
* usr/lib/byobu/.shutil: fix rounding across a decimal point in fpdiv()
|
||||||
|
|
|
@ -32,32 +32,39 @@ for arg in $@; do
|
||||||
done
|
done
|
||||||
|
|
||||||
# Try to use metadata service
|
# Try to use metadata service
|
||||||
zone=$(wget -q -O - http://169.254.169.254/latest/meta-data/placement/availability-zone || echo "us-east-1")
|
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%?}"
|
. "$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
|
type=$(wget -q -O - http://169.254.169.254/latest/meta-data/instance-type | sed -e "s/\./_/g")
|
||||||
eval RATE="\$$type"
|
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
|
else
|
||||||
# Count CPUs, Memory, Architecture
|
. "$BYOBU_PREFIX/share/$PKG/ec2/rates."*
|
||||||
|
# Count CPUs, Memory, Architecture, hours
|
||||||
cpu=$(grep -c "^processor.*:" /proc/cpuinfo) || cpu=1
|
cpu=$(grep -c "^processor.*:" /proc/cpuinfo) || cpu=1
|
||||||
mem=$(grep ^MemTotal /proc/meminfo | awk '{print $2}')
|
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)
|
# Guess this system's going rate, based on mem available (m* types)
|
||||||
if [ $mem -lt 700000 ]; then
|
if [ $mem -lt 700000 ]; then
|
||||||
RATE=$T1_MICRO
|
RATE=$t1_micro
|
||||||
elif [ $mem -gt 64000000 ]; then
|
elif [ $mem -gt 64000000 ]; then
|
||||||
RATE=$M2_4XLARGE
|
RATE=$m2_4xlarge
|
||||||
elif [ $mem -gt 32000000 ]; then
|
elif [ $mem -gt 32000000 ]; then
|
||||||
RATE=$M2_2XLARGE
|
RATE=$m2_2xlarge
|
||||||
elif [ $mem -gt 16000000 ]; then
|
elif [ $mem -gt 16000000 ]; then
|
||||||
RATE=$M2_XLARGE
|
RATE=$m2_xlarge
|
||||||
elif [ $mem -gt 14000000 ]; then
|
elif [ $mem -gt 14000000 ]; then
|
||||||
RATE=$M1_XLARGE
|
RATE=$m1_xlarge
|
||||||
elif [ $mem -gt 7000000 ]; then
|
elif [ $mem -gt 7000000 ]; then
|
||||||
RATE=$M1_LARGE
|
RATE=$m1_large
|
||||||
else
|
else
|
||||||
# Otherwise, scale based on number of cpu's (c* types)
|
# 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
|
||||||
fi
|
fi
|
||||||
|
hours=$(((`date +%s` - `stat --printf %Y $file_to_stat`) / 60 / 60 + 1))
|
||||||
|
|
||||||
# Data Transfer Cost Basis
|
# Data Transfer Cost Basis
|
||||||
# Incoming $0.10/GB
|
# 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}'`
|
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
|
# Calculate uptime cost
|
||||||
hours=$(((`date +%s` - `stat --printf %Z /etc/hostname`) / 60 / 60 + 1))
|
|
||||||
uptime_cost=`echo "$hours" | awk "{printf \"%f\", "$RATE" * $hours}"`
|
uptime_cost=`echo "$hours" | awk "{printf \"%f\", "$RATE" * $hours}"`
|
||||||
total_cost=`echo "$network_cost" "$uptime_cost" | awk '{printf "%.2f", $1 + $2}'`
|
total_cost=`echo "$network_cost" "$uptime_cost" | awk '{printf "%.2f", $1 + $2}'`
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
ec2dir = $(datadir)/@PACKAGE@/ec2
|
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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue