mtthwcmpbll / spring-boot-carbon-metrics

This repository is a project to automatically instrument a Spring Boot app with carbon-aware sustainability metrics.
Apache License 2.0
7 stars 4 forks source link

Spring Boot Carbon-Aware Metrics

The Problem

This project has three goals:

  1. Make it easy to measure and see the carbon impact of Spring Boot applications, while they're running and while they're doing specific work
  2. Make it easy to measure and see that impact across multiple services interacting with each other
  3. Make it easy for lots of developers to get that same data and measure improvements towards their sustainability goals

Carbon Aware Starter

The carbon-aware-starter lies at the heart to this project's offering. It provides the following actuator endpoints and prometheus metrics out of the box to monitor the spring boot apps.

Sl. Actuator Endpoint Prometheus metrics Description
1 /actuator/carbon/emissions carbon_emissions It provides the marginal carbon intensity from the Carbon-Aware SDK for the application's location.
2 /actuator/carbon/sci carbon_sci It provides SCI (Software Carbon Intensity) score of the application

The sci score is calculated by a formulae SCI = ((E * I) + M). For this calculation the following interfaces are provided :

The starter also provides out-of-the-box implementations for each of the above interfaces, but they can also be easily overidden if an implementation is added for these interfaces in the spring boot app which is using this starter. The default implementations are as follows :

The starter provides the following properties which needs to be configured for using:

Sl. Property Description
1 spring.carbon-aware.enabled This property needs to be set as true to enable the starter. The default value is false.
2 spring.carbon-aware.endpoint This property points to base endpoint of carbon-aware-sdk. A value neeeds to be passed if starter is enabled.
3 spring.carbon-aware.location This property points to location for which the emissions are calculated. Default value is "".
4 spring.carbon-aware.embodiedEmissions This property points to the emboided emissions for the hardware. Default value is 0.0

Quickstart

In the same example there are two services hello-service and weather-service where we have added the carbon-aware-starter. To start the project do the following steps :