From 0129e9065519bd81b3b0d69ba71f773780a3e209 Mon Sep 17 00:00:00 2001 From: Dustin Kirkland Date: Mon, 8 Jun 2009 11:45:10 -0500 Subject: [PATCH] * bin/ec2-cost: performance improvement, cache ifconfig output Signed-off-by: Dustin Kirkland --- bin/ec2-cost | 6 ++++-- debian/changelog | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/bin/ec2-cost b/bin/ec2-cost index 3b669154..fd2d3dc0 100755 --- a/bin/ec2-cost +++ b/bin/ec2-cost @@ -52,9 +52,11 @@ TX_RATE="0.17" # Auto detect network interface IF=`/sbin/route -n | grep "0\.0\.0\.0" | tail -n1 | awk '{print $8}'` +ifconfig_out=`/sbin/ifconfig "$IF"` + # Calculate bandwidth cost -tx_gb=`/sbin/ifconfig "$IF" | grep "TX bytes:" | sed "s/^.*TX bytes://" | awk '{ printf "%f", $1 / 1024 / 1024 / 1024 }'` -rx_gb=`/sbin/ifconfig "$IF" | grep "RX bytes:" | sed "s/^.*RX bytes://" | awk '{ printf "%f", $1 / 1024 / 1024 / 1024 }'` +tx_gb=`echo "$ifconfig_out" | grep "TX bytes:" | sed "s/^.*TX bytes://" | awk '{ printf "%f", $1 / 1024 / 1024 / 1024 }'` +rx_gb=`echo "$ifconfig_out" | grep "RX bytes:" | sed "s/^.*RX bytes://" | 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 diff --git a/debian/changelog b/debian/changelog index d89bc9b0..6c261f4d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -7,8 +7,9 @@ byobu (2.9) unreleased; urgency=low * bin/cpu-count: performance improvement, use getconf * bin/cpu-freq: performance improvement, simplify pipes * bin/disk-*: use the POSIX output format + * bin/ec2-cost: performance improvement, cache ifconfig output - -- Dustin Kirkland Mon, 08 Jun 2009 11:40:33 -0500 + -- Dustin Kirkland Mon, 08 Jun 2009 11:44:07 -0500 byobu (2.8-0ubuntu1) karmic; urgency=low