mirror of
https://github.com/dustinkirkland/byobu
synced 2025-08-21 22:13:19 -07:00
* usr/lib/byobu/ec2_cost, usr/lib/byobu/hostname,
usr/lib/byobu/include/shutil, usr/lib/byobu/ip_address: LP: #894038 - background all wgets, as these can be expensive (cough OpenStack cough) - sleep for 0.02 seconds after each wget, as most EC2 wgets take less than 0.01 seconds, but some might take longer - after backgrounded wget and sleep, attempt to read the results of the wget from a cache file; if this succeeds, proceed and use it - if not, fail through gracefully, and pick up the results from the cach file on the next run
This commit is contained in:
parent
6ec5e1b29a
commit
3aaa914c97
5 changed files with 54 additions and 22 deletions
9
debian/changelog
vendored
9
debian/changelog
vendored
|
@ -10,6 +10,15 @@ byobu (4.50) unreleased; urgency=low
|
||||||
* usr/share/byobu/profiles/tmux:
|
* usr/share/byobu/profiles/tmux:
|
||||||
- fix action bar color
|
- fix action bar color
|
||||||
* usr/lib/byobu/include/mondrian:
|
* usr/lib/byobu/include/mondrian:
|
||||||
|
* usr/lib/byobu/ec2_cost, usr/lib/byobu/hostname,
|
||||||
|
usr/lib/byobu/include/shutil, usr/lib/byobu/ip_address: LP: #894038
|
||||||
|
- background all wgets, as these can be expensive (cough OpenStack cough)
|
||||||
|
- sleep for 0.02 seconds after each wget, as most EC2 wgets take less
|
||||||
|
than 0.01 seconds, but some might take longer
|
||||||
|
- after backgrounded wget and sleep, attempt to read the results of the
|
||||||
|
wget from a cache file; if this succeeds, proceed and use it
|
||||||
|
- if not, fail through gracefully, and pick up the results from the
|
||||||
|
cach file on the next run
|
||||||
|
|
||||||
-- Dustin Kirkland <kirkland@ubuntu.com> Fri, 18 Nov 2011 15:41:36 -0600
|
-- Dustin Kirkland <kirkland@ubuntu.com> Fri, 18 Nov 2011 15:41:36 -0600
|
||||||
|
|
||||||
|
|
|
@ -32,18 +32,19 @@ __ec2_cost_detail() {
|
||||||
}
|
}
|
||||||
|
|
||||||
__ec2_cost() {
|
__ec2_cost() {
|
||||||
local zone type file_to_stat cpu mem rate hours tx_gb rx_gb network_cost uptime_cost total_cost interface
|
local zone type file_to_stat cpu mem rate hours tx_gb rx_gb network_cost uptime_cost total_cost interface cache="$BYOBU_RUN_DIR/cache.$BYOBU_BACKEND/ec2_cost"
|
||||||
# Try to use metadata service
|
# Try to use metadata service
|
||||||
if metadata_available; then
|
if metadata_available; then
|
||||||
zone=$(wget -q -O - http://169.254.169.254/latest/meta-data/placement/availability-zone)
|
[ -s "$cache.zone" ] || wget -q -O "$cache.zone" http://169.254.169.254/latest/meta-data/placement/availability-zone 2>/dev/null &
|
||||||
if [ ! -r "$BYOBU_PREFIX/share/$PKG/ec2/rates.${zone%?}" ]; then
|
sleep 0.02
|
||||||
zone="us-east-1d"
|
[ -s "$cache.zone" ] && read zone < "$cache.zone"
|
||||||
fi
|
[ -r "$BYOBU_PREFIX/share/$PKG/ec2/rates.${zone%?}" ] || zone="us-east-1d"
|
||||||
. "$BYOBU_PREFIX/share/$PKG/ec2/rates.${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")
|
[ -s "$cache.type" ] || wget -q -O "$cache.type" http://169.254.169.254/latest/meta-data/instance-type 2>/dev/null &
|
||||||
|
sleep 0.02
|
||||||
|
[ -s "$cache.type" ] && type=$($SED -e "s/\./_/g" "$cache.type")
|
||||||
eval rate="\$$type"
|
eval rate="\$$type"
|
||||||
file_to_stat="$BYOBU_RUN_DIR/cache.$BYOBU_BACKEND/ec2_cost.instance_type"
|
file_to_stat="$cache.type"
|
||||||
[ -f "$file_to_stat" ] || wget -q -O "$file_to_stat" http://169.254.169.254/latest/meta-data/instance-type
|
|
||||||
fi
|
fi
|
||||||
if [ -z "$rate" ]; then
|
if [ -z "$rate" ]; then
|
||||||
. "$BYOBU_PREFIX/share/$PKG/ec2/rates."*
|
. "$BYOBU_PREFIX/share/$PKG/ec2/rates."*
|
||||||
|
|
|
@ -24,9 +24,13 @@ __hostname_detail() {
|
||||||
}
|
}
|
||||||
|
|
||||||
__hostname() {
|
__hostname() {
|
||||||
|
local h=
|
||||||
if metadata_available; then
|
if metadata_available; then
|
||||||
# We're in EC2, so get our public hostname
|
local cache="$BYOBU_RUN_DIR/cache.$BYOBU_BACKEND/hostname"
|
||||||
h=$(wget -q -O - http://169.254.169.254/latest/meta-data/public-hostname)
|
# Background a retrieval of our public hostname
|
||||||
|
wget -q -O "$cache" http://169.254.169.254/latest/meta-data/public-hostname 2>/dev/null &
|
||||||
|
sleep 0.02
|
||||||
|
[ -s "$cache" ] && read h < "$cache"
|
||||||
else
|
else
|
||||||
h=$(hostname -s 2>/dev/null || hostname)
|
h=$(hostname -s 2>/dev/null || hostname)
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -209,11 +209,21 @@ metadata_available() {
|
||||||
# This is really ugly. We need a reliable, fast way of determining
|
# This is really ugly. We need a reliable, fast way of determining
|
||||||
# if a metadata service is available, that does NOT slow down non-ec2
|
# if a metadata service is available, that does NOT slow down non-ec2
|
||||||
# machines.
|
# machines.
|
||||||
if [ -e /etc/ec2_version ] || [ -e /usr/sbin/update-grub-legacy-ec2 ]; then
|
local x=0 cache="$BYOBU_CONFIG_DIR/.metadata_available"
|
||||||
wget -q -O- --timeout=1 --tries=1 http://169.254.169.254 >/dev/null 2>&1
|
# First, check the cache
|
||||||
|
if [ -s "$cache" ]; then
|
||||||
|
# Metadata is non-empty, so we have metadata available
|
||||||
|
x=1
|
||||||
else
|
else
|
||||||
false
|
# Must seed the cache
|
||||||
|
if [ -e /etc/ec2_version ] || [ -e /usr/sbin/update-grub-legacy-ec2 ]; then
|
||||||
|
# This *looks* like a machine with metadata, so background a potentially slow check
|
||||||
|
wget -q -O "$cache" --timeout=10 --tries=1 http://169.254.169.254 2>/dev/null &
|
||||||
|
sleep 0.02
|
||||||
|
[ -s "$cache" ] && x=1
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
[ "$x" = "1" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
status_freq() {
|
status_freq() {
|
||||||
|
|
|
@ -26,7 +26,7 @@ __ip_address_detail() {
|
||||||
}
|
}
|
||||||
|
|
||||||
__ip_address() {
|
__ip_address() {
|
||||||
local interface ipaddr
|
local interface ipaddr cache="$BYOBU_RUN_DIR/cache.$BYOBU_BACKEND/ip_address"
|
||||||
# Allow interface overrides in $BYOBU_CONFIG_DIR/statusrc
|
# Allow interface overrides in $BYOBU_CONFIG_DIR/statusrc
|
||||||
if [ -n "$MONITORED_NETWORK" ]; then
|
if [ -n "$MONITORED_NETWORK" ]; then
|
||||||
interface="$MONITORED_NETWORK"
|
interface="$MONITORED_NETWORK"
|
||||||
|
@ -39,21 +39,29 @@ __ip_address() {
|
||||||
case "$IPV6" in
|
case "$IPV6" in
|
||||||
1|true|yes)
|
1|true|yes)
|
||||||
if [ "$IP_EXTERNAL" = "1" ]; then
|
if [ "$IP_EXTERNAL" = "1" ]; then
|
||||||
ipaddr=$(wget -O- -q http://v6.ipv6-test.com/api/myip.php)
|
# Background an update
|
||||||
|
wget -q -O "$cache" http://v6.ipv6-test.com/api/myip.php 2>/dev/null &
|
||||||
|
sleep 0.02
|
||||||
else
|
else
|
||||||
ipaddr=$(LC_ALL=C /sbin/ip -6 addr list dev "$interface" scope global 2>/dev/null)
|
# Background an update
|
||||||
|
LC_ALL=C /sbin/ip -6 addr list dev "$interface" scope global >"$cache" 2>/dev/null &
|
||||||
|
fi
|
||||||
|
[ -s "$cache" ] && read ipaddr < "$cache"
|
||||||
# Print 'None' if we have no global address
|
# Print 'None' if we have no global address
|
||||||
[ -z "$ipaddr" ] && ipaddr="None"
|
[ -z "$ipaddr" ] && ipaddr="None"
|
||||||
ipaddr=${ipaddr#* inet6 }
|
ipaddr=${ipaddr#* inet6 }
|
||||||
ipaddr=${ipaddr%%/*}
|
ipaddr=${ipaddr%%/*}
|
||||||
fi
|
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
if [ "$IP_EXTERNAL" = "1" ]; then
|
if [ "$IP_EXTERNAL" = "1" ]; then
|
||||||
ipaddr=$(wget -O- -q http://v4.ipv6-test.com/api/myip.php)
|
wget -q -O "$cache" http://v4.ipv6-test.com/api/myip.php 2>/dev/null &
|
||||||
|
sleep 0.02
|
||||||
|
[ -s "$cache" ] && read ipaddr < "$cache"
|
||||||
elif metadata_available; then
|
elif metadata_available; then
|
||||||
# We're in EC2, so get our public IP address
|
# We're in EC2, so get our public IP address
|
||||||
ipaddr=$(wget -q -O- http://169.254.169.254/latest/meta-data/public-ipv4)
|
wget -q -O "$cache" http://169.254.169.254/latest/meta-data/public-ipv4 2>/dev/null &
|
||||||
|
sleep 0.02
|
||||||
|
[ -s "$cache" ] && read ipaddr < "$cache"
|
||||||
else
|
else
|
||||||
ipaddr=$(LC_ALL=C /sbin/ip -4 addr list dev "$interface" scope global 2>/dev/null)
|
ipaddr=$(LC_ALL=C /sbin/ip -4 addr list dev "$interface" scope global 2>/dev/null)
|
||||||
ipaddr=${ipaddr#* inet }
|
ipaddr=${ipaddr#* inet }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue