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

Science Score: 23.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
    Links to: arxiv.org, ieee.org
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (8.7%) to scientific vocabulary

Keywords from Contributors

sustainability carbon-footprint
Last synced: 9 months ago · JSON representation

Repository

A tool written in go to help you factor carbon intensity into decisions about where and when to run computing jobs.

Basic Info
  • Host: GitHub
  • Owner: thegreenwebfoundation
  • License: apache-2.0
  • Language: Go
  • Default Branch: main
  • Homepage:
  • Size: 3.98 MB
Statistics
  • Stars: 80
  • Watchers: 4
  • Forks: 10
  • Open Issues: 14
  • Releases: 9
Created over 5 years ago · Last pushed almost 2 years ago
Metadata Files
Readme Changelog License

README.md

GoDoc go-unit-test docker kubernetes nomad

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

sh brew install thegreenwebfoundation/carbon-aware-tools/grid-intensity

  • Install via curl (feel free to do due diligence and check the script first).

sh 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.

sh $ 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.

sh $ 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.

sh $ 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 gridintensitycarbon_average Average carbon intensity for the electricity grid in this location.

TYPE gridintensitycarbon_average gauge

gridintensitycarbon_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.

sh 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.

sh 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.

sh 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.

sh 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.

sh 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

sh 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.

sh grid-intensity --provider=CarbonIntensityOrgUK --location=UK

Owner

  • Name: The Green Web Foundation
  • Login: thegreenwebfoundation
  • Kind: organization
  • Email: dev@thegreenwebfoundation.org
  • Location: The Internet

The Green Web Foundation - Let's make the web green

GitHub Events

Total
  • Issues event: 2
  • Watch event: 16
  • Issue comment event: 2
  • Fork event: 2
Last Year
  • Issues event: 2
  • Watch event: 16
  • Issue comment event: 2
  • Fork event: 2

Committers

Last synced: 10 months ago

All Time
  • Total Commits: 75
  • Total Committers: 6
  • Avg Commits per committer: 12.5
  • Development Distribution Score (DDS): 0.173
Past Year
  • Commits: 12
  • Committers: 4
  • Avg Commits per committer: 3.0
  • Development Distribution Score (DDS): 0.333
Top Committers
Name Email 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 (Top 20 + Academic)

Issues and Pull Requests

Last synced: 10 months ago

All Time
  • 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 requests: 53
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 3
  • Pull requests: 1
  • Average time to close issues: 1 day
  • Average time to close pull requests: 6 days
  • Issue authors: 3
  • Pull request authors: 1
  • Average comments per issue: 1.67
  • Average comments per pull request: 1.0
  • Merged pull requests: 1
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • mrchrisadams (10)
  • rossf7 (10)
  • fershad (5)
  • ofpiyush (1)
  • ZeidH (1)
  • davidheijkamp (1)
  • Lennart01 (1)
  • locomundo (1)
  • davidkopp (1)
Pull Request Authors
  • rossf7 (50)
  • locomundo (4)
  • fershad (2)
  • ofpiyush (2)
  • ZeidH (2)
  • mrchrisadams (1)
Top Labels
Issue Labels
gwf-green-code-challenge (5) documentation (1) No coding needed (1) good first issue (1)
Pull Request Labels

Packages

  • 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
  • Versions: 9
  • Dependent Packages: 0
  • Dependent Repositories: 1
Rankings
Dependent repos count: 4.8%
Stargazers count: 7.1%
Average: 7.3%
Dependent packages count: 8.5%
Forks count: 8.9%
Last synced: 9 months ago

Dependencies

go.mod go
  • 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
go.sum go
  • 865 dependencies
.github/workflows/docker-integration-test.yaml actions
  • actions/checkout v3 composite
  • docker/build-push-action v3 composite
  • docker/setup-buildx-action v2 composite
  • docker/setup-qemu-action v2 composite
.github/workflows/docker-release.yaml actions
  • 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
.github/workflows/go-releaser.yaml actions
  • actions/checkout v3 composite
  • actions/setup-go v3 composite
  • getsentry/action-github-app-token main composite
  • goreleaser/goreleaser-action v3 composite
.github/workflows/go-unit-test.yaml actions
  • actions/checkout v2 composite
.github/workflows/kubernetes-integration-test.yaml actions
  • 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
.github/workflows/nomad-integration-test.yaml actions
  • actions/checkout v3 composite
  • docker/build-push-action v3 composite
  • docker/setup-buildx-action v2 composite
  • docker/setup-qemu-action v2 composite
Dockerfile docker
  • alpine 3.16 build