Monitoring Cloud Service Charges

08/17/2011 05:59 pm

Meter’s running - How to avoid spending all your money—

Ever been in a cab, stuck in traffic watching the meter run. You watch each 50-cent increment nudge the fair up dollar by dollar, wondering if it would be quicker to walk.

Cloud hosting is charged the same way, but it’s very easy to take your eye off the meter, fire up dozens of services, store gigabytes of files, and end up spending a fortune.

I’ve left instances sitting around for days and even weeks. Between myself and our lead architect, we somehow forgot about an RDS instance for a few days, racking up charges for a machine that wasn’t even being used.

It doesn’t matter what platform you use: If it’s pay as you go, you’ll want to monitor it to prevent your $1,000-a-month bill turning into $10,000 a month.

In the tradition of programmers being lazy but resourceful, I’ve thrown together a little script using the Ruby cloud computing library fog that shows you which services are running and roughly how much they’re charging in the current hour.

The script simply connects to AWS, finds each of the main chargeable services (I’ve only done EC2, RDS, and S3 so far … feel free to contribute), and uses a table of costs to find the upper limit of costs. Because AWS tiers its price (the second million gigabytes of storage cost less than the first), the estimated costs will probably be higher than you are charged at the end of the month, but it’s better to be safe ….

Write the Script

The first few lines list the instances I use and their costs. Because I’m only working in a couple of regions, I’ve left the costs approximate.

instance_costs = {
   't1.micro'   => 0.02,
   'm1.small'   => 0.095,
   'c1.medium'  => 0.19,
   'm2.2xlarge' => 1.14,
   'm2.4xlarge' => 2.28

Then I list the regions. This could have been dynamic, but I don’t want to check in the [asia??] regions, so I’ve listed them.

regions = [

And finally, I need the account details. Because I run multiple accounts for dev, test, and production for multiple clients the account details are in a hash.

accounts = {
   'myaccount' => {
      'key_id' => 'YOUR-KEY-HERE',
      'access_key' => 'YOUR-ACCESS-KEY-HERE'

The script uses 'fog' [URL], which means you could adapt it to work with GoGrid, Rackspace, or whichever cloud provider you use.

The rest of the script simply loops through the accounts, then through the regions, and shows you how much you’re spending in the current hour and what that might be at the end of the month. It’s easy to forget that $1 an hour is $744 dollars a month.

Run the Script

$ ruby cost-checker.rb
For region 'eu-west-1'
   i-abc123ab....................: $  0.19
   i-def456de....................: $  0.095
   i-hij789hi....................: $  0.095
Total for account                : $  0.48
Projected monthly for account    : $353.40

Pretty useful. If an instance is stopped, it is shown because you won’t be charged for it.

   i-aaa111aa....................: $--.-- [stopped]

EC2 isn’t by any means the only way to rack up charges. You need to consider storage (S3, EBS snapshots, and CloudFront), bandwidth, and any other services you’re using. This script should help you keep an eye on the meter.

The script is available on github at Just clone it and run … then realize how much you should be saving.

Related content

  • Fathoming the cloud
    Much spoken of but little understood, "the cloud" poses new security problems that need to be defined and debated and their solutions facilitated.
  • A Real-World Look at Scaling to the Amazon Cloud
    The Amazon cloud environment adapts easily to custom solutions. We'll show you how one company built their solution in the cloud.
  • Build Your Own Cloud

    Cloud computing provides a variety of benefits including flexibility and control. However, in the case of infrastructure as a service, practically all public cloud service providers offer only a relatively small number of pre-configured virtual machine images. This is somewhat analogous to offering shoes without half-sizes or widths, and then – when the fit isn’t quite right – asking the customer to try on a brand or style that is sized a bit differently. The customer may end up with the right size, or the right brand, or the right style – but not all three. In the case of IaaS, this means settling for a server which does not fit the needs of an application in terms of CPU, memory or storage.

    SoftLayer has recently updated its renowned CloudLayer service with a Build Your Own Cloud capability. This new approach allows customers to configure the amount of CPU, memory and storage used by their cloud servers. With this enhanced capability, SoftLayer customers avoid the tradeoffs forced by other IaaS offerings. These tradeoffs typically include over provisioning, which leads to inefficient resource utilization and higher cost, or under provisioning, which leads to lower levels of performance and scalability. Rather than constraining the dimensions of your server, CloudLayer lets you customize your server to meet the specific needs of your application. After all, who knows your application best – you or your IaaS provider? Neovise believes that any organization wishing to run production applications in a public cloud needs to strongly consider SoftLayer. 

  • Exploring Ubuntu cloud tools
    Cloud computing, promising manageable, quickly deployed, virtual machines in large networks, is so appealing in a world where everyone is trying to cut costs. Ubuntu Enterprise Cloud Services (UEC) is Canonical's entry into the cloud market.
  • Delivering Cloud Services: Five Essentials for Success

    You can meet the challenges of delivering cloud services successfully and profitably, if you have the right identity management capabilities. This paper outlines the five infrastructure essentials for successfully delivering cloud services to a rapidly growing customer base. You'll learn how these essentials can benefit both you, the cloud services provider, and your customer, the cloud services consumer – to your ultimate economic benefit. Plus, we'll outline why traditional identity management infrastructures fall short, and how a new approach is the key to building the essentials into your business.

Dan Frost is Technical Director of, cloud hosting consultants and web developers based in London and Brighton, UK

Dan has been building cloud hosting, writing, and talking about the cloud since before it was trendy. Since he spun up his first AWS instance, he's been trying out new services and finding ways of getting more out of hardware without actually owning any of it.

Mon Tue Wed Thu Fri Sat Sun
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29