[ec2-beta] Can I retrieve the current cost of a running instance?
Eric Hammond
ehammond at thinksome.com
Wed Feb 4 23:30:52 GMT 2009
Dustin:
The EC2 instance type calculation is a bit more complex than number of
CPUs. Both c1.medium($0.20/hr) and m1.large($0.40/hr) have 2 processors.
The accurate instance type for the current instance is available at:
http://169.254.169.254/latest/meta-data/instance-type/
With the current instance types, you might be able to guess the correct
one based on the processors, memory, and architecture. More info:
http://ec2types.notlong.com
Keep in mind that Amazon will surely be adding more instance types in
the future.
--
Eric Hammond
ehammond at thinksome.com
Dustin Kirkland wrote:
> 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,
>
More information about the Ec2-beta
mailing list