Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cloudyspells/carbon-appinsights
Azure Function for logging PSElectricityMaps results for Azure regions to Application Insights
https://github.com/cloudyspells/carbon-appinsights
azure bicep carbon-emissions carbon-footprint cloud green-software powershell
Last synced: 3 months ago
JSON representation
Azure Function for logging PSElectricityMaps results for Azure regions to Application Insights
- Host: GitHub
- URL: https://github.com/cloudyspells/carbon-appinsights
- Owner: cloudyspells
- License: mit
- Created: 2023-04-23T13:35:10.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-04-30T21:29:36.000Z (over 1 year ago)
- Last Synced: 2024-05-14T05:03:16.988Z (6 months ago)
- Topics: azure, bicep, carbon-emissions, carbon-footprint, cloud, green-software, powershell
- Language: Bicep
- Homepage:
- Size: 272 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
Carbon AppInsights
==================Log ElectricityMaps Emissions data for Azure regions to AppInsights
-------------------------------------------------------------------This is a simple Azure Function App that logs the emissions data for Azure
regions to AppInsights. From Application Insights and the configured Log
Analytics workspace, you can create dashboards and alert rules to use in scaling
operations and feature flags.The function is triggered by a timer every 20 minutes. The function will log
a metric `{region}CarbonIntensity` for each region in the configured list of
regions. The metric value is the carbon intensity in grams of CO2 per kWh.Sample use cases can be found in the
[carbon-appinsights-samples](https://github.com/cloudyspells/carbon-appinsights-samples)
repository.![Example AppInsights Dashboard](./docs/images/log-weu-co2-insights-dev.png)
### Usage
This function is designed to be deployed to Azure as a Function App with the
included _GitHub Workflow_ using bicep. See [the local guide](docs/usage-local.md)
for instructions your local workstation.
To deploy the function, you will need fork this repository and create a new
GitHub repository secret named `AZURE_CREDENTIALS` with the value of the output
from the following command:```bash
az ad sp create-for-rbac --name "CarbonAppInsights" --sdk-auth --role contributor --scopes /subscriptions/
```You will also need a secret named `AZURE_SUBSCRIPTION_ID` with the value of your
Azure subscription ID.You will need to register for an API token at ElectricityMaps and add it as a
secret named `EMTOKEN` to your repository.Then run the deployment workflow by running the _Deploy Bicep code_ workflow
configured in your forked repository from the file
`.github/workflows/deploy-bicep.yml`.### Configuration
To configure your own deployment, you will need to edit the
`src/bicep/main.parameters.json` with your own desired configuration.#### Parameters
| Name | Type | Default | Description |
| --- | --- | --- | --- |
|`projectName`|`string`|`carbon-appinsights`|The name of the project. Used in naming resources|
|`environment`|`string`|`dev`|The name of the environment. Used in naming resources|
|`location`|`string`|`westeurope`|The Azure region to deploy the resources to|
|`emToken`|`securestring`|`null`|The ElectricityMaps API token. Should be specified in cmdline with env var|
|`emissionRegions`|`string`|"westeurope","norwayeast","northeurope"|The list of regions to log emissions data for|### Deployed resources
The following resources are deployed by the bicep template:
| Type | Description |
| --- | --- |
|KeyVault|A KeyVault to store the ElectricityMaps API key|
|FunctionApp|An Azure Function App to run the PowerShell function|
|ApplicationInsights|An Application Insights instance to log the emissions data|
|LogAnalyticsWorkspace|A Log Analytics workspace to store the emissions data|
|StorageAccount|A Storage Account to store the Function App code|
|AppServicePlan|An App Service Plan to host the Function App|