Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion docs/documentation/sitespeed.io/sustainable/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ By default the hosting data (knowing if a host is green) is collected from a loc

You can also disable the hosting match (all hosts will be treated as grey hosting) with `--sustainable.disableHosting`.

### Country-based electricity data

You can optionally specify a country code to calculate carbon emissions using a specific electricity grid mix (via electricitymaps):
example:-
```bash
sitespeed.io https://example.com \
--plugins.add sustainable \

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the rest of the documentation we use --sustainable.enable, I think we should use that here too.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense I can update the result page to also show which countryCode was used, so it’s clear what configuration the CO₂ calculation is based on and for documentation I will make a update shortly.

--sustainable.countryCode IN
```

## How it works

### Short version
Expand Down Expand Up @@ -110,4 +120,4 @@ Larger data centres have historically been cited close to sources of cheap power

For the rest of the internet, we use the [International Energy Agency's](https://hyp.is/MPRiUlTMEeq13bM-WjChjQ/www.iea.org/reports/global-energy-co2-status-report-2019/emissions) figure from of 475g of CO2 per kilowatt hour for for 2018, as an average across the globe.

Where we know power is generated using renewables we use the figure from the UK's regulator Ofgem, for renewables including solar, wind and hydroelectricity, of 33.4 grammes of CO2 per kilowatt hour. To tell how a site is powered, we look up the domain with the Green Web Foundation's - either via the their API, or when available, using their publicly available [url2green](https://www.thegreenwebfoundation.org/green-web-datasets/) dataset.
Where we know power is generated using renewables we use the figure from the UK's regulator Ofgem, for renewables including solar, wind and hydroelectricity, of 33.4 grammes of CO2 per kilowatt hour. To tell how a site is powered, we look up the domain with the Green Web Foundation's - either via the their API, or when available, using their publicly available [url2green](https://www.thegreenwebfoundation.org/green-web-datasets/) dataset.
13 changes: 13 additions & 0 deletions lib/plugins/sustainable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ export default class SustainablePlugin extends SitespeedioPlugin {
super({ name: 'sustainable', options, context, queue });
}

static getCliOptions() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work? I think the options for now could be moved to lib/cli/cli.js where the rest of the sustainable options is today, to keep it consistent.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works I have tested it locally switching between two different country codes shows different result in different CO2 values and I will move and test it on cli.js to ensure consistency and get back to you shorty

return {
'sustainable.countryCode': {
describe:
'ISO driven country code used to calculate country specific carbon intensity via electricity-maps',
type: 'string'
}
};
}

async open(context, options) {
this.storageManager = context.storageManager;
this.options = options;
Expand Down Expand Up @@ -162,6 +172,9 @@ export default class SustainablePlugin extends SitespeedioPlugin {
if (this.sustainableOptions.model === 'swd') {
configuration.version = this.sustainableOptions.modelVersion;
}
if (this.sustainableOptions.countryCode) {
configuration.countryCode = this.sustainableOptions.countryCode;
}
const CO2 = new co2(configuration);
const co2PerDomain = perDomain(message.data, hostingGreenCheck, CO2);
const baseDomain = message.data.baseDomain;
Expand Down
Loading