grid-intensity-go
A tool written in go to help you factor carbon intensity into decisions about where and when to run computing jobs.
https://github.com/thegreenwebfoundation/grid-intensity-go
Category: Consumption
Sub Category: Computation and Communication
Keywords from Contributors
sustainable carbon-footprint
Last synced: about 6 hours ago
JSON representation
Repository metadata
A tool written in go to help you factor carbon intensity into decisions about where and when to run computing jobs.
- Host: GitHub
- URL: https://github.com/thegreenwebfoundation/grid-intensity-go
- Owner: thegreenwebfoundation
- License: apache-2.0
- Created: 2020-11-03T11:31:35.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-08-29T15:48:04.000Z (8 months ago)
- Last Synced: 2025-04-17T23:00:31.673Z (10 days ago)
- Language: Go
- Homepage:
- Size: 3.98 MB
- Stars: 77
- Watchers: 4
- Forks: 9
- Open Issues: 14
- Releases: 9
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
README.md
grid-intensity-go
A tool written in Go, designed to be integrated into Kubernetes, Nomad, and other schedulers, to help you factor carbon intensity into decisions about where and when to run jobs.
The tool has 3 components.
- The
grid-intensity
CLI for interacting with carbon intensity data. - A Prometheus exporter with carbon intensity metrics that can be deployed via
Docker, Nomad, or Kubernetes. - A Go library that can be integrated into your Go code.
Changelog
See CHANGELOG.md.
Background
We know that the internet runs on electricity. That electricity comes from a mix of energy sources, including wind and solar, nuclear power, biomass, fossil gas, oil and coal and so on,
We call this the fuel mix, and this fuel mix can impact on the carbon intensity of your code.
Move your code through time and space
Because the fuel mix will be different depending when and where you run your code, you can influence the carbon intensity of the code you write by moving it through time and space - either by making it run when the grid is greener, or making it run where it's greener, like a CDN running on green power.
Inspired By
This tool builds on research and tools developed from across the sustainable software community.
Articles
- A carbon aware internet - Branch magazine - https://branch.climateaction.tech/issues/issue-2/a-carbon-aware-internet/
- Carbon Aware Kubernetes - https://devblogs.microsoft.com/sustainable-software/carbon-aware-kubernetes/
- Clean energy technologies threaten to overwhelm the grid. Here’s how it can adapt. - https://www.vox.com/energy-and-environment/2018/11/30/17868620/renewable-energy-power-grid-architecture
Papers
- A Tale of Two Visions: Designing a Decentralized Transactive Electric System - https://ieeexplore.ieee.org/document/7452738
- Carbon Explorer - https://github.com/facebookresearch/CarbonExplorer/
- Cucumber: Renewable-Aware Admission Control for Delay-Tolerant Cloud and Edge Workloads - https://arxiv.org/abs/2205.02895
- Let's Wait Awhile: How Temporal Workload Shifting Can Reduce Carbon Emissions in the Cloud - https://arxiv.org/abs/2110.13234
Tools
- Carbon Aware Nomad - experimental branch - https://github.com/hashicorp/nomad/blob/h-carbon-meta/CARBON.md
- Cloud Carbon Footprint - https://www.cloudcarbonfootprint.org/
- Scaphandre - https://github.com/hubblo-org/scaphandre
- Solar Protocol - http://solarprotocol.net/
- The carbon aware scheduler - https://pypi.org/project/carbon-aware-scheduler/
Installing
- Install via brew.
brew install thegreenwebfoundation/carbon-aware-tools/grid-intensity
- Install via curl (feel free to do due diligence and check the script first).
curl -fsSL https://raw.githubusercontent.com/thegreenwebfoundation/grid-intensity-go/main/install.sh | sudo sh
- Fetch a binary release from the releases page.
grid-intensity CLI
The CLI allows you to interact with carbon intensity data from multiple providers.
$ grid-intensity
Provider ember-climate.org needs an ISO country code as a location parameter.
ESP detected from your locale.
ESP
[
{
"emissions_type": "average",
"metric_type": "absolute",
"provider": "Ember",
"location": "ESP",
"units": "gCO2e per kWh",
"valid_from": "2021-01-01T00:00:00Z",
"valid_to": "2021-12-31T23:59:00Z",
"value": 193.737
}
]
The --provider
and --location
flags allow you to select other providers and locations.
You can also set the GRID_INTENSITY_PROVIDER
and GRID_INTENSITY_LOCATION
environment
variables or edit the config file at ~/.config/grid-intensity/config.yaml
.
$ grid-intensity --provider CarbonIntensityOrgUK --location UK
{
"from": "2022-07-14T14:30Z",
"to": "2022-07-14T15:00Z",
"intensity": {
"forecast": 184,
"actual": 194,
"index": "moderate"
}
}
The providers section shows how to configure other providers.
grid-intensity exporter
The exporter
subcommand starts the prometheus exporter on port 8000.
$ grid-intensity exporter --provider Ember --location FR
Using provider "Ember" with location "FR"
Metrics available at :8000/metrics
View the metrics with curl.
$ curl -s http://localhost:8000/metrics | grep grid
# HELP grid_intensity_carbon_average Average carbon intensity for the electricity grid in this location.
# TYPE grid_intensity_carbon_average gauge
grid_intensity_carbon_average{provider="Ember",location="FR",units="gCO2 per kWh"} 67.781 1718258400000
Note about Prometheus and samples in the past
If you are using the exporter with the ElectricityMaps provider, it will return a value for estimated, which will be the most recent one, and another value for the real value, which can be a few hours in the past. Depending on your Prometheus installation, it could be that the metrics that have a timestamp in the past are not accepted, with an error such as this:
Error on ingesting samples that are too old or are too far into the future
In that case, you can configure the property tsdb.outOfOrderTimeWindow
to extend the time window accepted, for example to 3h
.
Docker Image
Build the docker image to deploy the exporter.
CGO_ENABLED=0 GOOS=linux go build -o grid-intensity .
docker build -t thegreenwebfoundation/grid-intensity:latest .
Kubernetes
Install the helm chart in /helm/grid-intensity-exporter.
Needs the Docker image to be available in the cluster.
helm install --set gridIntensity.location=FR grid-intensity-exporter helm/grid-intensity-exporter
Nomad
Edit the Nomad job in /nomad/grid-intensity-exporter.nomad to set the
env vars GRID_INTENSITY_LOCATION
and GRID_INTENSITY_PROVIDER
Start the Nomad job. Needs the Docker image to be available in the cluster.
nomad run ./nomad/grid-intensity-exporter.nomad
grid-intensity-go library
See the /examples/
directory for examples of how to integrate each provider.
Providers
Currently these providers of carbon intensity data are integrated. If you would like
us to integrate more providers please open an issue.
Electricity Maps
Electricity Maps have carbon intensity data
from multiple sources. You need to get an API token and URL from their
API portal to use the API. You can use
their free tier for non-commercial use or sign up for a 30 day trial.
The location
parameter needs to be set to a zone present in the public zones endpoint.
ELECTRICITY_MAPS_API_TOKEN=your-token \
ELECTRICITY_MAPS_API_URL=https://api-access.electricitymaps.com/free-tier/ \
grid-intensity --provider=ElectricityMaps --location=IN-KA
WattTime
WattTime have carbon intensity data from multiple sources.
You need to register to use the API.
The location
parameter should be set to a supported location. The /ba-from-loc
endpoint allows you to provide a latitude and longitude. See the docs for more details.
WATT_TIME_USER=your-user \
WATT_TIME_PASSWORD=your-password \
grid-intensity --provider=WattTime --location=CAISO_NORTH
Ember
Carbon intensity data from Ember, is embedded in the binary
in accordance with their licensing - CC-BY-SA 4.0
grid-intensity --provider=Ember --location=DE
The location
parameter should be set to a 2 or 3 char ISO country code.
UK Carbon Intensity API
UK Carbon Intensity API https://carbonintensity.org.uk/ this is a public API
and the only location supported is UK
.
grid-intensity --provider=CarbonIntensityOrgUK --location=UK
Owner metadata
- Name: The Green Web Foundation
- Login: thegreenwebfoundation
- Email: [email protected]
- Kind: organization
- Description: The Green Web Foundation - Let's make the web green
- Website: https://www.thegreenwebfoundation.org
- Location: The Internet
- Twitter: greenwebfound
- Company:
- Icon url: https://avatars.githubusercontent.com/u/8995024?v=4
- Repositories: 69
- Last ynced at: 2024-10-30T03:50:10.533Z
- Profile URL: https://github.com/thegreenwebfoundation
GitHub Events
Total
- Issues event: 2
- Watch event: 14
- Issue comment event: 2
- Fork event: 2
Last Year
- Issues event: 2
- Watch event: 14
- Issue comment event: 2
- Fork event: 2
Committers metadata
Last synced: 6 days ago
Total Commits: 75
Total Committers: 6
Avg Commits per committer: 12.5
Development Distribution Score (DDS): 0.173
Commits in past year: 12
Committers in past year: 4
Avg Commits per committer in past year: 3.0
Development Distribution Score (DDS) in past year: 0.333
Name | Commits | |
---|---|---|
Ross Fairbanks | r****7 | 62 |
Chris Adams | c****s@p****k | 4 |
fershad | 2****d | 4 |
locomundo | f****a@a****m | 2 |
Piyush Mishra | p****h@c****m | 2 |
Zeid Adabel | 3****H | 1 |
Committer domains:
Issue and Pull Request metadata
Last synced: 1 day ago
Total issues: 33
Total pull requests: 56
Average time to close issues: 4 months
Average time to close pull requests: 6 days
Total issue authors: 9
Total pull request authors: 6
Average comments per issue: 3.03
Average comments per pull request: 1.25
Merged pull request: 53
Bot issues: 0
Bot pull requests: 0
Past year issues: 5
Past year pull requests: 5
Past year average time to close issues: 20 days
Past year average time to close pull requests: 6 days
Past year issue authors: 5
Past year pull request authors: 3
Past year average comments per issue: 4.2
Past year average comments per pull request: 1.8
Past year merged pull request: 5
Past year bot issues: 0
Past year bot pull requests: 0
Top Issue Authors
- mrchrisadams (11)
- rossf7 (11)
- fershad (5)
- ofpiyush (1)
- ZeidH (1)
- davidheijkamp (1)
- Lennart01 (1)
- locomundo (1)
- davidkopp (1)
Top Pull Request Authors
- rossf7 (48)
- ofpiyush (2)
- locomundo (2)
- fershad (2)
- ZeidH (1)
- mrchrisadams (1)
Top Issue Labels
- gwf-green-code-challenge (6)
- good first issue (2)
- documentation (1)
- No coding needed (1)
- enhancement (1)
- help wanted (1)
Top Pull Request Labels
Package metadata
- Total packages: 1
- Total downloads: unknown
- Total dependent packages: 0
- Total dependent repositories: 1
- Total versions: 9
proxy.golang.org: github.com/thegreenwebfoundation/grid-intensity-go
- Homepage: https://github.com/thegreenwebfoundation/grid-intensity-go
- Documentation: https://pkg.go.dev/github.com/thegreenwebfoundation/grid-intensity-go#section-documentation
- Licenses: Apache-2.0
- Latest release: v0.7.0 (published 11 months ago)
- Last Synced: 2025-04-26T14:03:08.194Z (1 day ago)
- Versions: 9
- Dependent Packages: 0
- Dependent Repositories: 1
-
Rankings:
- Dependent repos count: 4.794%
- Stargazers count: 7.096%
- Average: 7.311%
- Dependent packages count: 8.453%
- Forks count: 8.902%
Dependencies
- github.com/Xuanwo/go-locale v1.1.0
- github.com/beorn7/perks v1.0.1
- github.com/cenkalti/backoff/v4 v4.1.3
- github.com/cespare/xxhash/v2 v2.1.2
- github.com/fsnotify/fsnotify v1.5.4
- github.com/gofrs/flock v0.8.1
- github.com/golang/protobuf v1.5.2
- github.com/google/go-cmp v0.5.8
- github.com/hashicorp/hcl v1.0.0
- github.com/inconshreveable/mousetrap v1.0.0
- github.com/jellydator/ttlcache/v2 v2.11.1
- github.com/magiconair/properties v1.8.6
- github.com/matttproud/golang_protobuf_extensions v1.0.1
- github.com/mitchellh/mapstructure v1.5.0
- github.com/pelletier/go-toml v1.9.5
- github.com/pelletier/go-toml/v2 v2.0.1
- github.com/prometheus/client_golang v1.12.2
- github.com/prometheus/client_model v0.2.0
- github.com/prometheus/common v0.32.1
- github.com/prometheus/procfs v0.7.3
- github.com/rodaine/table v1.0.1
- github.com/spf13/afero v1.8.2
- github.com/spf13/cast v1.5.0
- github.com/spf13/cobra v1.4.0
- github.com/spf13/jwalterweatherman v1.1.0
- github.com/spf13/pflag v1.0.5
- github.com/spf13/viper v1.12.0
- github.com/subosito/gotenv v1.3.0
- golang.org/x/lint v0.0.0-20210508222113-6edffad5e616
- golang.org/x/sync v0.0.0-20220513210516-0976fa681c29
- golang.org/x/sys v0.0.0-20220708085239-5a0f0661e09d
- golang.org/x/text v0.3.7
- golang.org/x/tools v0.1.5
- google.golang.org/protobuf v1.28.0
- gopkg.in/ini.v1 v1.66.4
- gopkg.in/yaml.v2 v2.4.0
- gopkg.in/yaml.v3 v3.0.0
- 865 dependencies
- actions/checkout v3 composite
- docker/build-push-action v3 composite
- docker/setup-buildx-action v2 composite
- docker/setup-qemu-action v2 composite
- actions/checkout v3 composite
- docker/build-push-action v3 composite
- docker/login-action v2 composite
- docker/metadata-action v4 composite
- docker/setup-buildx-action v2 composite
- docker/setup-qemu-action v2 composite
- actions/checkout v3 composite
- actions/setup-go v3 composite
- getsentry/action-github-app-token main composite
- goreleaser/goreleaser-action v3 composite
- actions/checkout v2 composite
- actions/checkout v3 composite
- azure/setup-helm v3 composite
- azure/setup-kubectl v3 composite
- docker/build-push-action v3 composite
- docker/setup-buildx-action v2 composite
- docker/setup-qemu-action v2 composite
- helm/kind-action v1.3.0 composite
- actions/checkout v3 composite
- docker/build-push-action v3 composite
- docker/setup-buildx-action v2 composite
- docker/setup-qemu-action v2 composite
- alpine 3.16 build
Score: 6.302618975744904