|
| 1 | +--- |
| 2 | +title: "Carbon Intensity - Elephant - Machine" |
| 3 | +description: "Documentation for CarbonIntensityElephantMachineProvider of the Green Metrics Tool" |
| 4 | +date: 2026-05-11T08:49:15+00:00 |
| 5 | +weight: 221 |
| 6 | +--- |
| 7 | + |
| 8 | +### What it does |
| 9 | + |
| 10 | +This provider fetches the carbon intensity (gCO2e/kWh) of the electricity grid from a self-hosted |
| 11 | +or remotely hosted [Elephant](https://github.com/green-coding-solutions/elephant) service. |
| 12 | +Elephant is a small HTTP service developed by us which aggregates carbon |
| 13 | +intensity data from multiple upstream sources (e.g. Bundesnetzagentur, Electricity Maps, ...) and exposes |
| 14 | +them through a uniform REST interface. It also offers the ability to *simulate* arbitrary carbon |
| 15 | +intensity curves so that the same workload can be re-evaluated under different grid scenarios. |
| 16 | + |
| 17 | +This provider integrates Elephant into the Green Metrics Tool so that every run automatically |
| 18 | +gets a carbon intensity time series for the configured region and data provider attached to it |
| 19 | +without leaking any information to a third party. |
| 20 | + |
| 21 | +### Classname |
| 22 | + |
| 23 | +- `CarbonIntensityElephantMachineProvider` |
| 24 | + |
| 25 | +### Metric Name |
| 26 | + |
| 27 | +- `carbon_intensity_elephant_machine` |
| 28 | + |
| 29 | +### Unit |
| 30 | + |
| 31 | +- `gCO2e/kWh` |
| 32 | + |
| 33 | +The provider stores integer values. The API returns floating point numbers which are rounded to |
| 34 | +the nearest integer before being persisted. |
| 35 | + |
| 36 | +### Prerequisites & Installation |
| 37 | + |
| 38 | +The provider is a pure Python provider and does not need any binary to be compiled. It does |
| 39 | +however require a reachable Elephant service. Elephant can be self-hosted via Docker; please |
| 40 | +follow the instructions in the |
| 41 | +[Elephant repository](https://github.com/green-coding-solutions/elephant) for the setup. |
| 42 | + |
| 43 | +The provider must be configured in the `config.yml`: |
| 44 | + |
| 45 | +```yml |
| 46 | +measurement: |
| 47 | + metric-providers: |
| 48 | + common: |
| 49 | + carbon_intensity_elephant_machine: |
| 50 | + region: 'DE' |
| 51 | + sampling_rate: 99 # Remove if you don't want value padding |
| 52 | + provider: 'bundesnetzagentur' |
| 53 | + elephant: |
| 54 | + host: localhost |
| 55 | + port: 8085 |
| 56 | + protocol: http |
| 57 | +``` |
| 58 | +
|
| 59 | +Please see [Configuration →]({{< relref "/docs/measuring/configuration" >}}) for further info. |
| 60 | +
|
| 61 | +### Input Parameters |
| 62 | +
|
| 63 | +- `region` — The region identifier as understood by Elephant (e.g. `DE`, `FR`). The list of |
| 64 | + supported regions depends on which upstream providers your Elephant instance has configured. |
| 65 | +- `provider` — The name of the carbon intensity data provider in Elephant to use (e.g. |
| 66 | + `bundesnetzagentur`, `entsoe`). |
| 67 | +- `elephant.host` — Host name or IP of the Elephant service. |
| 68 | +- `elephant.port` — Port the Elephant service listens on (default `8085`). |
| 69 | +- `elephant.protocol` — `http` or `https`. |
| 70 | +- `sampling_rate` — The sampling rate in milliseconds. As with the Electricity Maps provider this |
| 71 | + is used to *pad* the returned values so they align with the time series of the other providers |
| 72 | + rather than to query the API more often. |
| 73 | + |
| 74 | +### Output |
| 75 | + |
| 76 | +The provider does not produce a continuous Stdout stream. Once per run it queries the Elephant |
| 77 | +service and writes the results directly to the database as a metric of the run. |
| 78 | + |
| 79 | +Each row consists of: |
| 80 | + |
| 81 | +- `time`: The timestamp of the data point in microseconds (UNIX epoch). |
| 82 | +- `value`: The carbon intensity at that point in time in `gCO2e/kWh` as an integer. |
| 83 | +- `detail_name`: The name of the Elephant carbon provider that produced the value |
| 84 | + (e.g. `bundesnetzagentur_de`). For carbon simulation runs this is the simulation UUID. |
| 85 | + |
| 86 | +Any errors that occur while talking to the Elephant service are appended to the provider's stderr |
| 87 | +buffer and can be inspected in the run details in the frontend. |
| 88 | + |
| 89 | +### How it works |
| 90 | + |
| 91 | +On `start_profiling` and `stop_profiling` the provider records UTC timestamps. When the metrics |
| 92 | +are read at the end of the run it issues a single HTTP GET request to |
| 93 | + |
| 94 | +``` |
| 95 | +<protocol>://<host>:<port>/carbon-intensity/history |
| 96 | +``` |
| 97 | +
|
| 98 | +with the configured `region`, the start/end times of the run, the `provider` filter, and |
| 99 | +`update=true` so that Elephant re-fetches stale data from its upstream sources before responding. |
| 100 | +The response is a list of `{time, carbon_intensity, provider}` entries which are sorted, rounded |
| 101 | +to integer values and expanded to the configured `sampling_rate`. |
| 102 | +
|
| 103 | +If the response is empty — which typically happens for very short runs because upstream providers |
| 104 | +update at intervals between 5 minutes and one hour — the provider falls back to: |
| 105 | +
|
| 106 | +``` |
| 107 | +<protocol>://<host>:<port>/carbon-intensity/current |
| 108 | +``` |
| 109 | +
|
| 110 | +(or `/carbon-intensity/current/primary` if no provider filter is configured) and uses the most |
| 111 | +recent value as a single data point so that the run is never left without a carbon intensity. |
| 112 | +
|
| 113 | +### Health check |
| 114 | +
|
| 115 | +When the provider starts, it issues an HTTP GET against `/health` on the configured Elephant URL. |
| 116 | +The service is expected to respond with a JSON body containing `{"status": "healthy"}`. If the |
| 117 | +service is not reachable, returns a different status, or the response cannot be parsed, the |
| 118 | +provider raises a `MetricProviderConfigurationError` and the run will not start. |
| 119 | +
|
| 120 | +### Carbon simulation |
| 121 | +
|
| 122 | +The Elephant provider is also used by the Green Metrics Tool to drive *carbon simulations*. When |
| 123 | +running the runner with `--carbon-simulation <value>`: |
| 124 | +
|
| 125 | +- If `<value>` is a UUID, the simulation with that ID is used. |
| 126 | +- If `<value>` is a list of carbon values, the runner first POSTs it to Elephant's `/simulation` |
| 127 | + endpoint to register a new simulation, and then uses the returned UUID for the run. |
| 128 | +- If `<value>` is a single integer, that fixed intensity is applied to the whole run. |
| 129 | +
|
| 130 | +For simulation runs the provider sends `simulationId=<uuid>` as an additional query parameter to |
| 131 | +Elephant which then returns the simulated carbon intensity curve instead of the real grid data. |
| 132 | +Carbon simulations are useful to answer "what if?" questions such as how a workload would have |
| 133 | +behaved on a grid with a different generation mix without re-running the workload. |
| 134 | +
|
| 135 | +See the `--carbon-simulation` argument of `runner.py` for more details. |
| 136 | +
|
| 137 | +### Caveats |
| 138 | +
|
| 139 | +- The provider requires that the Elephant service is reachable from the measurement machine. If |
| 140 | + Elephant is hosted on a different network, make sure that firewalls and routing allow the |
| 141 | + connection. |
| 142 | +- The smallest temporal granularity supported by this provider depends on the upstream data |
| 143 | + provider configured in Elephant. Bundesnetzagentur for example updates roughly every 15 minutes. |
| 144 | +- The fallback to the `current` endpoint will yield only a single data point. Long runs should |
| 145 | + therefore always observe enough upstream data to avoid the fallback path. |
| 146 | +- Like all carbon intensity numbers in the Green Metrics Tool the values are stored as integers. |
| 147 | + Sub-`g/kWh` precision is lost; |
| 148 | +
|
| 149 | +### Troubleshooting |
| 150 | +
|
| 151 | +- *"Elephant base URL ... could not be reached"* — Check that `elephant.host`, `elephant.port`, |
| 152 | + and `elephant.protocol` are correct and that the Elephant service is running. Try |
| 153 | + `curl <protocol>://<host>:<port>/health` from the measurement machine. |
| 154 | +- *"Elephant service health check failed"* — Elephant responded but did not report `healthy`. |
| 155 | + Check the Elephant logs for missing upstream credentials or unreachable upstream APIs. |
| 156 | +- *"Please set the provider config option ..."* — You configured the provider without a |
| 157 | + `provider` entry and the run is not a carbon simulation. Either set `provider` in the |
| 158 | + `config.yml` or run with `--carbon-simulation`. |
| 159 | +- Empty time series in the frontend — The run was too short and even the fallback endpoint did |
| 160 | + not return a value. Increase the run duration or use a simulation. |
0 commit comments