Monitor the environmental impact of your EC2 instances with Cloud Scanner by Boavizta
Tags: cloud, aws, monitoring, greenit
Published: 2023-05-02 08:30:00

Nowadays, we can't ignore that **our way of life continually creates a debt towards the environment**, that's why the industry is more and more interested in the subject of Green IT and I was led to work on it via the **Responsible Digital Circle**, in my company **SFEIR**.

## The digital environmental context

According to studies, **digital technology is responsible for 4% of global greenhouse gas emissions**, and the sharp increase in uses suggests a doubling of this share by 2025 [(1)](#src-1).

At first sight, I thought that it could be easy to act to reduce this debt, that it was just a matter of time that we gave it, but entering the subject, I realized a bit more the complexity behind it. I took my first environmental slap and it's a good point because it encourages me to have a much more realistic approach (and I don’t even talk about greenwashing tendencies).

There are **different angles of attack we can focus on**, without being exhaustive : 

- **Increase sustainability of materials**, because production cost is heavy, and we can't rollback, when it's produced, it's too late.
- The **greenhouse gas emissions and electricity consumption** are the things we most commonly focus on, but **there are other criteria in the chain** of production that have a significant impact (like water consumption, mineral extraction, etc.).
- Care about the **different production methods for our materials**, because it really depends on the methods behind it, following the political choices of countries (for instance, in France, gas emissions for electricity are low, with the strong choice for nuclear power).
- We can **differentiate methodologies for servers and devices** (laptops, smartphones, computers, screens), usually devices have a bigger production cost, and **for servers, it is more relevant to focus on power consumption** (but it also depends on how materials are created, the balance may tip the other way)
- We can determine different scopes for the gas emissions [(2)](#src-2)
- It is more than relevant to look at the impact of data centers in general and the cloud in particular. Even the latest measurements provided by **Amazon recognize that it represents 71.54 million tons of CO2 per year**, in the world, constantly increasing over the years, despite the desire to move towards zero emissions. [(3)](#src-3)
- We can also act on the development itself, and the UX/UI **eco-conception** (Are all the features useful ? Are they inexpensive in resources ?) [(4)](#src-4)
- There is work to do also about **recycling solutions** and giving products a second life.
- In the near future, we can imagine that governments set clear guidelines to follow to limit the environmental impacts, and maybe penalties, but for now we have to count on the initiative of people in companies and voluntary associations. **Digital is just a part of the movement**, which can therefore be seen from an overall improvement perspective.

## Monitor environmental impact in the cloud

As a Cloud Engineer, I wanted a solution to estimate the carbon footprint of my resources on the Cloud. To start, I was interested in AWS which is the provider I know best.

**In the cloud**, we don’t have access to lower layers of the machines, so **we can't rely on low level probes to measure power consumption**.

We just naturally know that the fewer resources we use, the less we consume, but precise metrics will help you to have a global vision and to be more relevant.

AWS has recently offered a calculator, the **[Customer Carbon Footprint Tool](https://aws.amazon.com/fr/aws-cost-management/aws-customer-carbon-footprint-tool/)** to assess the environmental impact, which gives a [MTCO2EQ](https://climatejargonbuster.ie/kb/mtco2eq/) measure for EC2, S3 and other managed services, by geography (APAC, AMER, EMEA).


![AWS carbon footprint](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6729ul60e80cr7xu1f02.png)

This is an interesting tool, still a work in progress, but my attention fell on another tool, focused on EC2 instances and providing more specific metrics so far than the tool provided by Amazon.

## Monitor environmental impact with Cloud Scanner

**[Boavizta](https://www.boavizta.org/en) is an association that provides commons and open source tools to help us in our approach to limit the digital environmental impact**.

Among these commons, Boavizta provides **[Cloud Scanner](https://github.com/Boavizta/cloud-scanner), a solution to monitor the environmental impact of EC2 instances**.

As we do not have access to the lower layers of the machines, Boavizta has implemented methodologies to estimate data which has resulted in **an API to assess the environmental impact : [Boavizta API](https://www.boavizta.org/en/blog/boavizta-api-automated-evaluation-of-ict-impacts-on-the-environment)**.

The API is based to follow the **Life Cycle Assessment** (LCA) which includes all stages of product energy consumption and not just usage. [(5)](#src-5)

We can for instance evaluate the consumption of a t3.micro instance : 
```bash
curl -X 'POST' \
'https://api.boavizta.org/v1/cloud/aws?instance_type=t3.micro&verbose=false&allocation=TOTAL' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "hours_use_time": 2,
  "usage_location": "FRA"
  }' | jq
{
  "gwp": {
    "manufacture": 38,
    "use": 0.003,
    "unit": "kgCO2eq"
  },
  "pe": {
    "manufacture": 490,
    "use": 0.3,
    "unit": "MJ"
  },
  "adp": {
    "manufacture": 0.0036,
    "use": 1e-09,
    "unit": "kgSbeq"
  }
}
```

**GWP** (Global Warming Potential) refers to the global warming potential of a gas emitted into the atmosphere (measured in **[kgCO2eq](https://ec.europa.eu/eurostat/statistics-explained/index.php?title=Glossary:Carbon_dioxide_equivalent)** : Kilogram of Carbon dioxide Equivalent).

**PE** (Primary Energy Use) refers to energy in its raw form, before it has been converted by humans into other forms of energy like electricity, heat or transport fuels (measured in **[MJ](https://en.wikipedia.org/wiki/Joule)** : MegaJoule).

**ADP** (Abiotic Resource Depletion, mineral & metal) is one of the most commonly deliberate classes of impact on abiotic resources, which are non-living natural substances, such as copper ore and crude oil, and may contain energy resources, such as wind power (measured in **[kgSbeq](https://www.designingbuildings.co.uk/wiki/Abiotic_depletion_potential)** : Kilogram Antimony(symbol: Sb) Equivalent).

As [explained in the documentation](https://doc.api.boavizta.org/Explanations/boavizta_db/), data is collected by Boavizta manually or with scrappers referring to the manufactures declarations.


An endpoint is available to try the API : "**api.boavizta.org**", but you have to **host it on your own server**, it can be easily done with the serverless framework.
```bash
# Install the serverless framework and plugins
npm install -g serverless
npm i

# Authenticate
export AWS_PROFILE=your-own-profile

# Deploy
serverless deploy

```

**CloudScanner uses the Boavizta API**, and simplifies the use of this API by providing a turnkey solution, combining it with real-time usage data from your current AWS account, to provide a holistic view of the impacts of your EC2 instances by regions.

## Let's try Cloud Scanner

If you already have running instances on your AWS account, you can quickly try the solution like this : 

```bash
export AWS_PROFILE=your-own-profile

git clone git@github.com:Boavizta/cloud-scanner.git
cd cloud-scanner

docker-compose up
```

For a proper installation, you can install it with serverless, following this design : 


![Cloud Scanner AWS Serverless Design](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/18sqlpsu5t3ylgttj8kr.png)


You should now have access to the Grafana UI here : http://localhost:3001.

Then you will find the dashboard in **Browse Dashboards > General > Environmental impacts of cloud** :


![Cloud Scanner Grafana Dashboard](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h5iv2g598aq0mwdcsny5.png)


## Let's read the metrics

For demonstration purpose, I created three t3-micro instances, that can be compared : 
- one in France (eu-west-3)
- one in Ireland (eu-west-1)
- one in Germany (eu-central-1)

So we have three instances assessed, all these regions are covered by the tool, and we retrieve our indicators published by the Boavizta API : PE, GWP and ADP.

We can differentiate two different **scopes** : 
- **Manufacture** (displayed here for the entire server lifecyle, not amortized)
- **Use** (displayed here for one hour of use)

About the Manufacture scope, we can see the three regions have equivalent consumption, according to the indicators. 

About the Use scope, we can see consumptions are différent between the three regions.

**Primary energy use** is more expensive in Germany (0.0800 MJ) than in Ireland and France, where they are equivalent (0.0500 MJ).

**GWP use** is more expensive in Germany and Ireland (0.00200 kgco2eq) than in France (0.000500 kgco2eq).

**ADP use** is more expensive in Germany (4e-10 kgSbEq), followed by France (2e-10 kgSbEq), then Ireland (1e-10 kgSbEq).

What we can deduce is that the environmental impacts are different between these three regions, Germany being the most expensive in terms of energy according to these indicators, where France is more interesting for GWP and Ireland for ADP.

In addition, it is possible to view this data and export it in CSV or PNG format, via the [Datavizta](https://dataviz.boavizta.org) tool which is provided, to integrate this data as part of a larger study that you would like to undertake.


## Conclusion

With Cloud Scanner, you have specific and relevant data about energy use of your EC2 instances on AWS, you can **implement it in your global approach to limit digital environmental impact**.

It's an **open source** product, feel free to use it and maybe even participate, the creators are actively working on evolutions and constantly searching for contributors.

In the end, I would say that metrics are important to give you levers for action, the more relevant they are, the better. But they should not constitute an obstacle to **adopting a certain form of global sobriety in the way of designing projects, thinking about their purpose and extending the life of the equipment**.




_Sources_ :

<a name="src-1"></a>(1) The Shift Project - [Climate crisis: The Unsustainable Use of Online Video](https://theshiftproject.org/en/article/unsustainable-use-online-video/) - 2019

<a name="src-2"></a>(2) Boavizta - [Digital & environment : How to evaluate server manufacturing footprint, beyond greenhouse gas emissions](https://boavizta.org/en/blog/empreinte-de-la-fabrication-d-un-serveur) - 2021

<a name="src-3"></a>(3) Amazon - Sustainability - [Our Carbon Footprint](https://sustainability.aboutamazon.com/environment/carbon-footprint) - 2021

<a name="src-4"></a>(4) [FR] Collectif Conception Numérique Responsable - [115 Web Ecodesign Best Practices](https://github.com/cnumr/best-practices)

<a name="src-5"></a>(5) Wikipedia - [Life-cycle assessment](https://en.wikipedia.org/wiki/Life-cycle_assessment)