Greenhopper 0.1.0
See the version list below for details.
dotnet add package Greenhopper --version 0.1.0
NuGet\Install-Package Greenhopper -Version 0.1.0
<PackageReference Include="Greenhopper" Version="0.1.0" />
paket add Greenhopper --version 0.1.0
#r "nuget: Greenhopper, 0.1.0"
// Install Greenhopper as a Cake Addin #addin nuget:?package=Greenhopper&version=0.1.0 // Install Greenhopper as a Cake Tool #tool nuget:?package=Greenhopper&version=0.1.0
Greenhopper - Decarbonize your Azure Functions!
Greenhopper is a small library that adds carbon aware capabilities to your code, converting your workload to a sustainable one, and thus environmentally friendlier.
How it works
It uses emissions forecast from Carbon Aware SDK that predicts an optimal window of execution for an estimated workload of X minutes within a specified time frame and for a specific Azure Region. It then uses that prediction to decide if the current execution is within the optimal window and subsequently allows or not the workload execution to complete.
The question it answer is, "I want to run an Azure Function in region West US for 5 minutes sometime within the next 8 hours. Is now the time?"
Getting started
If you prefere a to get you started, he it is CarbonAware.AzureFunction.Sample
Getting started requires four steps:
- Install the Greenhopper nuget package
- Add or update your
appsetings.json
- Configure Greenhopper in
Program.cs
- Use DI to ask the question!
Add the nuget package to your project
Install the Greenhopper nuget package, using any of your favorite ways.
Add or update your appsetings.json
{
"carbonAwareVars:ForecastDataSource": "WattTime",
"carbonAwareVars:proxy:useProxy": false,
"carbonAwareVars:proxy:url": "",
"carbonAwareVars:proxy:username": "",
"carbonAwareVars:proxy:password": "",
"wattTimeClient:username": "greenhopper",
"wattTimeClient:password": "$gr33nh0pp3r",
"greenhopper:ExecutionTimeFrameInHours": 8,
"greenhopper:EstimatedExecutionDurationInMinutes": 5,
"greenhopper:OnNoForecastContinue": false
}
Configure Greenhopper in Program.cs
using Greenhopper.HostingHostBuilderExtensions; // <-- Add the reference
using Microsoft.Extensions.Hosting;
new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureGreenhopper() // <-- Add the configuration
.Build()
.Run();
Use DI to ask the question!
public class CarbonAwareFunction1
{
private readonly IGreenhopperService _greenhopper;
public Function1(IGreenhopperService greenhopper)
{
_greenhopper = greenhopper;
}
[Function("CarbonAwareFunction1")]
public async Task Run([TimerTrigger("0 */5 * * * *")] TimerInfo timerInfo)
{
//Reads the environment variable REGION_NAME
// from either the local environment variables or from Azure predefined ones
// when deployed to Azure,
// and the ExecutionTimeFrameInHours and EstimatedExecutionDurationInMinutes
// from either appsettings.json or Azure Function Configuration
if (!await _greenhopper.IsOptimalWindowNowAsync())
{
return;
}
// - OR -
//Reads the environment variable REGION_NAME internally
// from either the local environment variables or from Azure predefined ones
// when deployed to Azure
if (!await _greenhopper.IsOptimalWindowNowAsync(ExecutionTimeFrameInHours:8, EstimatedExecutionDurationInMinutes:5))
{
return;
}
//Write your code here
}
}
Testing vs Production
Carbon Aware SDK (and subsequently Greenhopper) is depended on 3rd party data providers such as WattTime or ElectricityMaps to get the emissions for a requested region. For testing purposes, greenhooper uses watttime.org that gives you unlimited access to the Azure Region "West US" to try out the library and deploy your workloads.
For testing, you can use the username/password provided, but for production you need to create your own account using the following POST
request (there is no UI!):
POST /v2/register HTTP/1.1
Host: api2.watttime.org
Content-Type: application/json
Content-Length: 143
{
"username": "YOUR USERNAME",
"password": "YOUR PASSWORD ", //at least 8 characters, with at least 1 of each alpha, number and special characters
"email": "YOUR EMAIL",
"org": "YOUR NAME OR ORG"
}
References
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- CarbonAware (>= 1.0.0)
- CarbonAware.Aggregators (>= 1.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 214 | 4/29/2023 |
0.6.6 | 172 | 4/29/2023 |
0.6.5 | 177 | 4/29/2023 |
0.6.4 | 184 | 4/28/2023 |
0.6.3 | 177 | 4/28/2023 |
0.6.2 | 184 | 4/28/2023 |
0.5.2 | 186 | 4/28/2023 |
0.5.0 | 170 | 4/28/2023 |
0.4.0 | 257 | 3/8/2023 |
0.3.4 | 306 | 12/23/2022 |
0.3.3 | 301 | 12/23/2022 |
0.3.1 | 291 | 12/23/2022 |
0.2.3 | 318 | 12/19/2022 |
0.2.2 | 292 | 12/18/2022 |
0.2.1 | 294 | 12/18/2022 |
0.2.0 | 305 | 12/18/2022 |
0.1.0 | 305 | 12/18/2022 |
0.0.5 | 311 | 12/16/2022 |
0.0.4 | 312 | 12/16/2022 |