mlco2 / codecarbon

Track emissions from Compute and recommend ways to reduce their impact on the environment.
https://mlco2.github.io/codecarbon
MIT License
1.01k stars 158 forks source link

feat: prometheus pushgateway mode #395

Closed inimaz closed 1 year ago

inimaz commented 1 year ago

Related to #162. This PR pushes codecarbon metrics to a given Prometheus pushgateway.

See the README for how to use it.

inimaz commented 1 year ago

Done that! @benoit-cty See ac1107f08c30940a1e6457140cda3887a2ce3596. As well there is a test that is always failing (the one with the default-cpu-constant). It fails because sometimes it finds the cpu's TDP in the list of data/hardware/cpu_power.csv. And for that test to pass I need the machine to not be in that list :( For now as a quick fix I have commented it out (4f62cad1f308c846b70f6c514a5b4525657f1852). But best way it would be to arrive to mock the file when running the test.

inimaz commented 1 year ago

@benoit-cty Could you check this when you have the time? All tests are passing now. Thanks a lot!

ipower-cc commented 1 year ago

setup.py seems to missing the promethus_client dependency. When I import a downstream package such as flask-sustainable:

File "/home/ccc/ipower/webconsole/.venv/lib/python3.11/site-packages/codecarbon/__init__.py", line 6, in <module> from .emissions_tracker import ( File "/home/ccc/ipower/webconsole/.venv/lib/python3.11/site-packages/codecarbon/emissions_tracker.py", line 27, in <module> from codecarbon.output import ( File "/home/ccc/ipower/webconsole/.venv/lib/python3.11/site-packages/codecarbon/output.py", line 22, in <module> from codecarbon.prometheus.prometheus import Prometheus File "/home/ccc/ipower/webconsole/.venv/lib/python3.11/site-packages/codecarbon/prometheus/prometheus.py", line 3, in <module> from prometheus_client import push_to_gateway ModuleNotFoundError: No module named 'prometheus_client'

I don't see an extras option aside from 'viz' and 'dashboard'

benoit-cty commented 1 year ago

Yes, sorry for that, I quick-fixed it in : https://github.com/mlco2/codecarbon/pull/422/files#diff-60f61ab7a8d1910d86d9fda2261620314edcae5894d5aaa236b821c7256badd7 But it will be better to have an extra.