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.
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.
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 |
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.
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.
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")
|
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.
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)
|
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.
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.
Learn
-
Visit AMEE.com.
-
The first step toward using the AMEE
platform is to sign up for an access
key.
-
http://my.amee.com/developers
covers all aspects of using the AMEE API.
-
Visit the
AMEE data wiki.
-
Read "Introduction to AMEE" to see what is going on under the hood in terms of AMEE API access.
-
Realtimecarbon.org uses AMEE
to calculate the real-time carbon intensity of the U.K. power-generation
system.
-
Visit
IBM® Smarter Planet.
-
Check out Smart
Grid to learn about how IBM is helping utilities add a layer of digital
intelligence to their power grids.
-
See how
IBM and
Cisco System are collaborating on City of Amsterdam Smarter Energy Project.
-
Learn about
ISO-8601 on Wikipedia.
-
The GReen IT Report collects resources for green computing and building your green skills.
-
"Home energy monitoring with AMEE: Create an energy monitor using XML, Ruby, Rails, and Ajax" is a step-by-step tutorial showing how to access energy data and store it in the AMEE energy data warehousing system.
-
To listen to interesting interviews and discussions for software developers, check out developerWorks podcasts.
-
Stay current with developerWorks' Technical events and webcasts.
-
Follow developerWorks on Twitter.
-
Check out upcoming conferences, trade shows, webcasts, and other Events around the world that are of interest to IBM open source developers.
-
Visit the developerWorks Open source zone for extensive how-to information, tools, and project updates to help you develop with open source technologies and use them with IBM's products, as well as our most popular articles and tutorials.
-
Watch and learn about IBM and open source technologies and product functions with the no-cost developerWorks On demand demos.
Get products and technologies
-
Download
Ruby. You will need
V1.8.6 or greater.
-
Get amee-ruby, a
gem to provide a Ruby interface to the AMEE carbon calculator.
-
Innovate your next open source development project with IBM trial software, available for download or on DVD.
- Download
IBM product evaluation versions
or explore
the online trials in the IBM SOA Sandbox and get your hands on application development tools and middleware products from
DB2®, Lotus®, Rational®, Tivoli®, and WebSphere®.
Discuss
-
Join the It's
all about Green! group
on My developerWorks to connect with other developers about energy-efficient computing.
-
Participate in developerWorks blogs and get involved in the developerWorks community.
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.




