Calculate your computer's carbon footprint using AMEE

Monitoring carbon from ICT Systems

As the use of IT continues to increase, Information and Communication Technology (ICT) systems will make up a large proportion of CO2 emissions. ICT providers are trying to find ways to reduce these emissions through efficiency, cloud computing, or other approaches, but the monitoring of such systems is also an essential requirement. The Avoiding Mass Extinctions Engine (AMEE) platform provides a standard framework for tracking carbon emissions and implements a variety of calculation methodologies. Investigate some approaches to calculating ICT emissions that are possible using the AMEE platform, and check out Ruby scripts that enable the automatic monitoring of such systems.

James Smith, Development Manager, AMEE

James Smith is development manager at AMEE. He has a background in software engineering, having spent more than 10 years in C++ software development, on projects ranging from biometrics to flight simulation, as well as having a Ph.D. in 3-D animation algorithms. He has carried out substantial work in the environmental software sector, working on Web-based projects, such as The Carbon Diet and Green Thing before joining AMEE.



29 September 2009

Also available in Russian

Introduction

AMEE is a Web-based API that allows users to store and retrieve many forms of consumption data over long periods, while simultaneously applying recognized carbon calculation models to determine the environmental consequences of that consumption. It has been used by developers to deliver myriad energy-tracking and energy-management solutions.

Join the green groups on My developerWorks

Discuss topics and share resources about energy, efficiency, and the environment on the GReen IT Report space and the Green computing group on My developerWorks.

Not a member of My developerWorks? Join now!

The AMEE API consists of two parts: profiles and data. Your energy data is stored in a set of profiles. By storing this data over time, you can build up a history of energy use for your clients, your business, or yourself. The data area stores a huge array of standard models, including the GHG Protocol, SAP building assessment, carbon emissions factors for 150 countries and regions, and related methodologies. When you store your consumption data in a profile, these models are automatically applied to give a reliable carbon footprint for your energy use.

As a neutral aggregation platform, AMEE makes available a variety of methodologies for carbon calculation, which use different calculation techniques, different inputs, and different levels of accuracy. The choice of which of these to use is up to you and should be one of the first things you will decide when you use the platform. This choice will depend upon your reporting requirements, legal requirements, etc. In this article, we will use the monitoring of ICT emissions as a case study to highlight measurement techniques and the different results that can be obtained.


Using AMEE in Ruby

In this article, we will be writing scripts in Ruby. Therefore, we will use the AMEE Ruby gem to speed up development (see Resources). This library was developed by AMEE and abstracts away many of the details of authentication, HTTP, and XML parsing. To see what's going on under the hood in terms of API access, read "Introduction to AMEE" (see Resources). We assume a UNIX®-like environment for the scripts in this article, though most techniques could be adapted to the Windows® platform with a little work. All scripts developed here are available to download from the AMEE source-control system (see Resources).

To install the Ruby gem, you need Ruby V1.8.6 or greater and RubyGems V1.3.0 or greater. On your machine, run the following commands shown in Listing 1.

Listing 1. Installing the Ruby gem
sudo gem sources -a http://gems.github.com 
sudo gem install Floppy-amee

Using averaged figures

One way of estimating emissions from computer systems is to use a set of standardized figures published by DEFRA in the United Kingdom and represented in AMEE in the /home/appliances/computers category. This methodology uses simplified average figures to arrive at emission factors for various types of computer equipment. For instance, there is an emission value for a desktop PC, one for an LCD screen, etc. This methodology also includes estimates for power used while on standby.

To obtain a carbon emission value from AMEE, we need to create profile items for each piece of equipment we want to measure. Listing 2 creates an item that represents a desktop PC in a pre-existing profile.

Listing 2. Creating an item that represents a desktop PC in a pre-existing profile
#!/usr/bin/env ruby
require 'rubygems'
gem 'Floppy-amee'
require 'amee'

AMEE_SERVER = "stage.amee.com"
AMEE_USERNAME = "your_username"
AMEE_PASSWORD = "your_password"
AMEE_PROFILE = "E9561EE2B7D9" # Change for your profile UID
AMEE_CATEGORY = "/home/appliances/computers/generic"
AMEE_DRILL = "device=Personal%20Computers&rating=Desktop"

# Connect
amee = AMEE::Connection.new(AMEE_SERVER, AMEE_USERNAME, AMEE_PASSWORD)

# Get data item UID for desktop PC
uid = AMEE::Data::DrillDown.get(amee, "/data#{AMEE_CATEGORY}/drill?#{AMEE_DRILL}")
.data_item_uid

# Store item
category = AMEE::Profile::Category.get(amee, "/profiles/#{AMEE_PROFILE}
#{AMEE_CATEGORY}")
item = AMEE::Profile::Item.create(category, uid)

# Print result
puts item.total_amount

After making the connection to AMEE, we perform a drill-down query to get the correct data item for the information we want to store. We then create a profile item in the appropriate category using the data item UID obtained from the drill-down. The result comes back in the item response, which we print out for our reference. This desktop PC creates 230kg of CO2 per year.

Obviously, this is quite a rough figure. We can improve it by tracking more accurately when the computer is on. To do this, we set the start- and end-date parameters when we create our profile item. The next version of the script creates an entry for the day on which the script was run. If this script is run once a day, only days when the computer is on will be tracked in AMEE.

Listing 3. Tracking the computer only on days when the computer is on
# Store item
category = AMEE::Profile::Category.get(amee, "/profiles/#{AMEE_PROFILE}#{AMEE_CATEGORY}")
options = {
  :start_date => Date.today,
  :end_date => Date.today + 1.day
}
item = AMEE::Profile::Item.create(category, uid, options)

We can also add to the script the capability to track attached equipment, such as an LCD screen and by adding a name parameter (in this case, set to be the hostname of the PC), we can store multiple computers in the same profile so the profile could be used to represent an entire office. We could then set up the script on multiple machines and have them all submitting their data into the same profile.

Listing 4. Tracking attached equipment
hostname = 'hostname'

def store_item(connection, category, drill, name)
  # Get data item UID
  uid = AMEE::Data::DrillDown.get(connection, "/data#{AMEE_CATEGORY}/drill?
#{drill}").data_item_uid
  # Store item
  options = {
    :start_date => Date.today,
    :end_date => Date.today + 1.day,
    :name => name
  }
  AMEE::Profile::Item.create(category, uid, options)
end

store_item(amee, category, "device=Personal%20Computers&rating=Desktop", hostname)
store_item(amee, category, "device=Monitor&rating=LCD", hostname)

What do these emission figures actually mean? The best place to find this out is the AMEE data documentation (see Resources). That site explains all of the data in AMEE in great detail. In this case, it explains that the figures for computers are based on a typical usage pattern of 5 1/2 hours per day. This may not be accurate enough for your application, so let's try another methodology that should give us a more accurate result.


Estimating power usage

As a next step toward a more accurate measurement, let's assume you know the average power usage of your computer systems (in watts). This is easily obtained using a plug-in power monitor, for example. How could we use this more accurate figure in AMEE to work out emissions?

As we are using actual power figures, we don't want to use the computers category anymore, but instead want to deal with the exact amounts of electricity consumed. For this, we will use the electricity item in the /home/energy/quantity category. We also want to be a bit more accurate about how long the PC is on for, so let's store data once an hour (though it could be done more regularly if you wanted to). If we set up this script to run hourly, we should get a fairly accurate estimate of emissions.

Listing 5. Dealing with exact amounts of electricity consumed
#!/usr/bin/env ruby
require 'rubygems'
require 'amee'
require 'activesupport'

AMEE_SERVER = "stage.amee.com"
AMEE_USERNAME = "your_username"
AMEE_PASSWORD = "your_password"
AMEE_PROFILE = "E9561EE2B7D9" # Change for your profile UID
AMEE_CATEGORY = "/home/energy/quantity"
AMEE_DRILL = "type=electricity"
POWER_IN_KILOWATTS = 0.2
HOSTNAME = `hostname`

# Connect
amee = AMEE::Connection.new(AMEE_SERVER, AMEE_USERNAME, AMEE_PASSWORD)
category = AMEE::Profile::Category.get(amee, "/profiles/#{AMEE_PROFILE}
#{AMEE_CATEGORY}")

# Get data item UID
uid = AMEE::Data::DrillDown.get(amee, "/data#{AMEE_CATEGORY}/drill?
#{AMEE_DRILL}").data_item_uid



# Store item
time = Time.now
options = {
  :energyConsumption => POWER_IN_KILOWATTS,
  :energyConsumptionUnit => "kWh",
  :energyConsumptionPerUnit => "h",
  :start_date => time,
  :end_date => time + 1.hour,
  :name => HOSTNAME
}
item = AMEE::Profile::Item.create(category, uid, options)

# Print result
puts "#{item.total_amount} #{item.total_amount_unit}"

We need to supply some extra parameters here, as we need to tell AMEE how much energy we are using for each time period. In this case, since we're using a constant value of 200W (for instance), we just set the energyConsumption profile item value to 0.2. Because this is a measure of energy used, not power (which our 200W value is), we need to specify the units for this value to make sure everything is right. In this case, we set the units to be kilowatt-hours per hour, so we can put in our power value as-is.


Setting your country

The calculation in Listing 5 will use U.K. electricity emission factors by default. However, by setting the country value in the /metadata category, you can change this behavior for an entire profile. By setting this to the name or ISO code of your country, the appropriate electricity factor will be taken into account automatically. Listing 6 sets this parameter.

Listing 6. Setting the ISO code of your country
uid = AMEE::Data::DrillDown.get(amee, "/data/metadata/drill").data_item_uid
AMEE::Profile::Item.create_without_category(amee, "/profiles/#{AMEE_PROFILE}
/metadata", uid, :country => "US")

Real-time monitoring

The above methods can give a reasonably accurate estimate that may be sufficient for your needs. However, in some cases, we want to be even more accurate. For instance, we might want to work out a power value that changes minute by minute. For virtualized or cloud-based systems, this may be especially important, as emissions will be more closely related to load.

Unfortunately, there are no standard methods for measuring power built into most OS kernels, so we still have to use estimates. However, if we can come up with a model that converts various operating parameters to a power-usage figure, we should be able to calculate something meaningful.


Estimating power from CPU usage

The most obvious method to estimate power usage is to use CPU load as an indicator. We can measure CPU usage once a minute, convert the result into a power usage using a defined mathematical model, and submit the result to AMEE for a high-resolution estimate of emissions.

First, let's look at measuring CPU usage. Since we are assuming a UNIX-like system, we can make some system calls to get the information we need. First, we need to know the number of CPUs in the system, which is most easily obtained by using a few simple UNIX commands.

Listing 7. Determining the number of CPUs in the system
# Get number of processors
num_procs = 'cat /proc/cpuinfo | grep processor | wc -l'.to_i

Next, we need to get a total CPU usage for all running processes, then divide by the number of CPUs. This gives us our total CPU usage value.

Listing 8. Getting the total CPU usage value
# Get CPU usage
processes = 'ps -e -o pcpu,cmd | grep -v cpu.rb'
cpu_total = 0
processes.each do |proc|
  cpu_total += proc.to_f
end
cpu_total /= (num_procs*100.0)

The next step is to apply our model that relates this to power. For our purposes, we assume a linear relationship between CPU and power usage. If we can measure the power at 0-percent CPU (or as close as possible) and at 100 percent, we can assume a linear interpolation between the two. So, 50-percent CPU will use Pmin + (0.5 * (Pmax - Pmin)). The code for the linear model is shown below.

Listing 9. Linear model
# Calculate power
min_power = 0.15
max_power = 0.25
power = min_power + (cpu_total * (max_power - min_power))

The resulting power usage value is then submitted to AMEE.

Listing 10. Submitting the resulting power usage value to AMEE
# Store item
time = Time.now
options = {
  :energyConsumption => power,
  :energyConsumptionUnit => "kWh",
  :energyConsumptionPerUnit => "h",
  :start_date => time,
  :end_date => time + 1.minute,
  :name => HOSTNAME
}
item = AMEE::Profile::Item.create(category, uid, options)

Obviously, this is a very simple model, which only uses a single parameter and assumes a linear relationship. A more complex model should take into account other inputs, such as disk usage for processes that are disk-intensive, rather than CPU-intensive.


Real-time carbon calculation

Recently, Realtimecarbon.org was released in the United Kingdom, and it uses AMEE to calculate the real-time carbon intensity of the U.K. power-generation system (see Resources). As the methods of power generation change over the day due to shifts in demand, the amount of CO2 per kWh change. This may lead to some interesting possibilities for cloud computing, whereby virtualized machine instances are shifted continuously around the world to take advantage of the lowest carbon power and off-peak demand. This has been referred to as "chasing the moon," as in the United Kingdom at least, the lowest carbon power is available during the night.

Using this real-time data is as simple as using a different category to store your power data. If, instead of /home/energy/quantity, you use the GB data item in the category /home/energy/electricity/realTimeElectricity, you will get a carbon value that takes the instantaneous carbon intensity into account. The code for creating items in this category is fundamentally the same as above, with a few minor differences.

Listing 11. Getting a carbon value that takes the instantaneous carbon intensity into account
AMEE_CATEGORY = "/home/energy/electricity/realTimeElectricity"
AMEE_DRILL = "country=GB"
...
# Store item
time = Time.now
options = {
  :energyUsed => power,
  :energyUsedUnit => "kWh",
  :energyUsedPerUnit => "h",
  :start_date => time,
  :end_date => time + 1.minute,
  :name => HOSTNAME
}
item = AMEE::Profile::Item.create(category, uid, options)

Graphing emissions

Storing data is very useful, but often, we want to get some information back. In addition to the standard XML and JSON APIs, profile categories in AMEE can be viewed as Atom feeds, which are ideal for time-series data of the type we have been creating. The URLs are of the form http://username:password@stage.amee.com/profiles/{profile_uid}/home/energy/quantity.atom.

These feeds include each profile item in the category in date order and include special tags containing the carbon emissions for each one. By using tools such as Google Charts, it is easy to extract the data and produce a simple visual representation of the stored data.


Summary

In this article, we've looked at a variety of ways data can be stored in AMEE. In particular, we have created a series of scripts that allow computer systems to be automatically tracked and monitored through the AMEE platform. All the code for these scripts is available from the AMEE source-control system.

The choice of which calculation methodology to use is an essential part of getting started with the AMEE platform. Often, your particular application or client will determine what you will use, but AMEE also provides a series of off-the-shelf recommendations for particular scenarios on the AMEE data documentation site. To discuss your requirements, you can always send e-mail to help@amee.com for more information.

Resources

Learn

Get products and technologies

Discuss

Comments

developerWorks: Sign in

Required fields are indicated with an asterisk (*).


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Information in your profile (your name, country/region, and company name) is displayed to the public and will accompany any content you post, unless you opt to hide your company name. You may update your IBM account at any time.

All information submitted is secure.

Choose your display name



The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


All information submitted is secure.

Dig deeper into Open source on developerWorks


static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Open source
ArticleID=430829
ArticleTitle=Calculate your computer's carbon footprint using AMEE
publish-date=09292009