[ec2-beta] Can I retrieve the current cost of a running instance?
Dustin Kirkland
kirkland at ubuntu.com
Wed Feb 4 12:59:46 GMT 2009
On Tue, Feb 3, 2009 at 3:44 PM, Dustin Kirkland <kirkland at ubuntu.com> wrote:
> Is it possible from a command line within a currently running ec2
> instance to call out to AWS and retrieve the current cost in dollars
> of this instance?
>
> I suppose it might be roughly calc-able by measuring uptime and
> network traffic, multiplying by the cost basis, etc. But that seems
> really complicated.
Okay, so I've hacked up a fast-running script (attached) that is
intended to provide a realistic upper-bound estimated cost of a
currently running system.
It computes...
* Network charge
* Estimate both sent and received network traffic by looking at
*current* ifconfig statistics
* Caveat: this does not account for any no-charge internal traffic
* Caveat: it currently lacks logic for the multi-TB price breaks
(shouldn't be hard to add)
* Uptime charge
* Estimate your usage charge based on your *current* system uptime
* Caveat: It guesses your price bracket based on the number of cpu's
on the system (is this correct?)
* Caveat: I don't have the logic to determine US vs. European prices
yet (anyone?)
Finally, all of these are very minor and fast operations on the local
system (a lot of awk for math, actually), so it runs in like 1/10th of
a second (which is much faster than any curl call).
I've browsed the meta-data, but unless I'm missing some good stuff, I
haven't found much info there that would help me with this.
In the guests that I've tested, ec2-cost is accurate withing $0.01.
ec2-cost says $2.51, and Amazon's web interface tells me $2.52.
Anyone care to run the script and validate/invalidate its accuracy?
Improvements/contributions would be appreciated. I am including it as
part of the screen-profiles package I'm working on, whereby this
running total could be shown in as a status item at the bottom of
screen.
For a screenshot, note the ~$2.51 item in:
* http://people.ubuntu.com/~kirkland/Screenshot-ec2-cost.png
Thanks,
--
:-Dustin
Dustin Kirkland
Ubuntu Server Developer
Canonical, LTD
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ec2-cost
Type: application/octet-stream
Size: 2352 bytes
Desc: not available
Url : https://lists.ubuntu.com/mailman/private/ec2/attachments/20090204/d3507b5e/attachment-0002.obj
More information about the Ec2-beta
mailing list