Code Monkey home page Code Monkey logo

tracarbon's Introduction

Tracarbon Logo

example workflow pypi doc licence

πŸ“Œ Overview

Tracarbon is a Python library that tracks your device's energy consumption and calculates your carbon emissions.

It detects your location and your device automatically before starting to export measurements to an exporter. It could be used as a CLI with already defined metrics or programmatically with the API by defining the metrics that you want to have.

Read more in this article.

πŸ“¦ Where to get it

# Install Tracarbon
pip install tracarbon
# Install one or more exporters from the list
pip install 'tracarbon[datadog,prometheus,kubernetes]'

πŸ”Œ Devices: energy consumption

Devices Description
Mac βœ… Global energy consumption of your Mac (must be plugged into a wall adapter).
Linux ⚠️ Only with RAPL. See #1. It works with containers on Kubernetes using the Metric API if available.
Windows ❌ Not yet implemented. See #184.
Cloud Provider Description
AWS βœ… Use the hardware's usage with the EC2 instances carbon emissions datasets of cloud-carbon-coefficients.
GCP ❌ Not yet implemented.
Azure ❌ Not yet implemented.

πŸ“‘ Exporters

Exporter Description
Stdout Print the metrics in Stdout.
JSON Write the metrics in a JSON file.
Prometheus Send the metrics to Prometheus.
Datadog Send the metrics to Datadog.

πŸ—ΊοΈ Locations

Location Description Source
Worldwide Get the latest co2g/kwh in near real-time using the CO2Signal or ElectricityMaps APIs. See here for the list of available zones. CO2Signal API or ElectricityMaps
Europe Static file created from the European Environment Agency Emission for the co2g/kwh in European countries. EEA website
AWS Static file of the AWS Grid emissions factors. cloud-carbon-coefficients

βš™οΈ Configuration

The environment variables can be set from an environment file .env.

Parameter Description
TRACARBON_CO2SIGNAL_API_KEY The api key received from CO2Signal or ElectricityMaps.
TRACARBON_CO2SIGNAL_URL The url of CO2Signal is the default endpoint to retrieve the last known state of the zone, but it could be changed to ElectricityMaps.
TRACARBON_METRIC_PREFIX_NAME The prefix to use in all the metrics name.
TRACARBON_INTERVAL_IN_SECONDS The interval in seconds to wait between the metrics evaluation.
TRACARBON_LOG_LEVEL The level to use for displaying the logs.

πŸ”Ž Usage

Request your API key

  • Go to CO2Signal and get your free API key for non-commercial use, or go to ElectricityMaps for commercial use.
  • This API is used to retrieve the last known carbon intensity (in gCO2eq/kWh) of electricity consumed in your location.
  • Set your API key in the environment variables, in the .env file or directly in the configuration.
  • If you would like to start without an API key, it's possible, the carbon intensity will be loaded statistically from a file.
  • Launch Tracarbon πŸš€

Command Line

tracarbon run

API

from tracarbon import TracarbonBuilder, TracarbonConfiguration

configuration = TracarbonConfiguration() # Your configuration
tracarbon = TracarbonBuilder(configuration=configuration).build()
tracarbon.start()
# Your code
tracarbon.stop()

with tracarbon:
    # Your code

report = tracarbon.report() # Get the report

πŸ’» Development

Local: using Poetry

make init
make test-unit

πŸ›‘οΈ Licence

Apache License 2.0

πŸ“š Documentation

The documentation is hosted here: https://fvaleye.github.io/tracarbon/documentation

tracarbon's People

Contributors

baiello avatar dependabot[bot] avatar fvaleye avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

tracarbon's Issues

Create a file exporter

Description

Create a file exporter for Tracarbon.

Use Case
When Tracarbon is launched, it should be able to write everything to local files.

Add __main__.py for easier cli usage

Description

Python modules are not necessarily in path, so we may want to use python3 -m tracarbon run instead of tracarbon run.

This led to an error.

The actual way of running tracarbon with Python where installed modules are not on path is python3 -m tracarbon.cli.__init__.

The correct way of running a Python package is python3 -m [module_name] (see here an example on "why it's better" with pip).

If we create a __main__.py file at the root of the package, then Python will call it by default using only the name of the package.

Here's a small example:

$ mkdir a && nano a/__main__.py
$ cat a/__main__.py 
if __name__ == "__main__":
    print("Main!")
$ python3 a
Main!

Private cloud (k8s)

Does tracarbon work in a cloud infrastructure? (private cloud) to measure my application's power consumption in my container?

Improve doc

I think the readme or the doc website is missing some explanation regarding the output of the program.

I think that tracarbon.hardware_memory_usage and tracarbon.hardware_cpu_usage are expressed in percentage?

What about tracarbon.co2_emission? What is the unit? Same for tracarbon.energy_consumption.

How to read the json file (or output to stdout)? Do we need to create a graph in order to see the consumption? Do we need to calculate a median or an average value?

Missing `return` statements for linux & windows

Environment

Tracarbon version: latest from pip

Environment:

  • OS: kubuntu

Bug

What happened:

File "/usr/local/lib/python3.10/dist-packages/tracarbon/hardwares/sensors.py", line 63, in from_platform
tracarbon.exceptions.TracarbonException: This platform Linux is not yet implemented.

How to reproduce it:

Launch tracarbon on linux (or windows).

More details:

The (simple) fix is to add a return here and here (hardwares/sensors.py, lines 61 & 63).

There is an error in operation. I would like to ask you for help.

Hello, thank you for providing such an excellent project and code. I don’t understand something and would like to ask you for advice. After configuring the api, I ran the command tracarbon run in the terminal but an error was displayed. I would like to ask you for advice on which one should be run. Does the program or what other parts of the program need to be changed before it can run?
error:
ValueError: could not convert string to float: ''

Application-level tracking

Hello,
Is it possible for Tracarbon to track only my application's power consumption and carbon footprint or does it always measure the whole machine's power?
What if I have a container? Does that mean that if I have an application in that container, it will give me metrics only for my app?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.